introduction of running microsoft access 2000

46
Introduction of Running Microsoft Access 2000 Source: USC Database Course (SC485) Modified to Access 2000, 박우창 교수 Main Topics aDatabase 구축 aData 조작 aForms 사용 a응용(application)구축

Upload: others

Post on 21-Feb-2022

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction of Running Microsoft Access 2000

1

Introduction of Running Microsoft Access 2000

Source: USC Database Course (SC485) Modified to Access 2000, 박우창 교수

Main Topics

Database 구축Data 조작Forms 사용응용(application)구축

Page 2: Introduction of Running Microsoft Access 2000

2

Building a Database

개념(Conceptual) data designE-R model

Tables 생성E-R model => tablesAccess 2000 테이블 생성

database design 변경테이블 삭제와 이름변경(Deleting and renaming tables)

테이블 내 필드 변경(Modifying fields within a table)

E-R Model

Entity setsRelationship setskeysMapping constrains

Entity EntityRelationship

Key KeyAttribute Attribute

N 1

Page 3: Introduction of Running Microsoft Access 2000

3

E-R Model => Tables

Strong entity setsLoan (loan-number, amount)

Weak entity setsPayment (payment-number, pay-date, pay-amount)

Relationship setsRedundancy of tables (links weak and strong entity)⌧Loan-Payment (loan-number, payment-number)

Combination of tables (many-to-one)⌧Branch(name, location)---has---account(account-number, amount)

Creating tables in Access 2000

1. Create a blank database (courses), click New to create a new table.

Page 4: Introduction of Running Microsoft Access 2000

4

Creating tables in MS Access 97

2. Choose the Design View and click OK.

Creating tables in MS Access 97

3. Input the Fields Names, Descriptions, and select Data Types.

Page 5: Introduction of Running Microsoft Access 2000

5

Creating tables in MS Access 97

4. Define the primary key.

Creating tables in MS Access 97

5. Add indexes.

Page 6: Introduction of Running Microsoft Access 2000

6

Creating tables in MS Access 97

6. Input Index Name, choose Field Name and Sort Order.

Creating tables in MS Access 97

7. Save the table.

Page 7: Introduction of Running Microsoft Access 2000

7

Deleting and Renaming Tables

Right-click the mouse on the table name that you want to delete or rename.

Modifying Fields within a Table

Changing field nameOpen the table in Design View and change the field name

Page 8: Introduction of Running Microsoft Access 2000

8

Modifying Fields within a Table

Inserting and deleting fieldsOpen the table in Design View, use the toolbar or menus.

Modifying Fields within a Table

Copying fieldsOpen the table in Design View, use the Edit menu.

Page 9: Introduction of Running Microsoft Access 2000

9

Modifying Fields within a Table

Moving fieldsOpen the table in Design View, drag and drop the row selector.

Working with Data

Datasheets 사용view, change, sort and search data

질의처리(Creating and using queries)Select queriesAction queries

Importing, linking and exporting dataODBC (Open Database Connectivity)

SQL

Page 10: Introduction of Running Microsoft Access 2000

10

Using Datasheets

View data

Using Datasheets

Changing data (adding, modifying, copying, deleting)

Page 11: Introduction of Running Microsoft Access 2000

11

Using Datasheets

Modifying datasheet formatUsing the Format menu, you can:⌧Selecting fonts⌧Changing row height and column width⌧Moving columns⌧Hiding and showing columns⌧freezing columns⌧Removing gridlines

Using Datasheets

Sorting and searching dataSorting using toolbar and searching using Find... in Edit menu

Page 12: Introduction of Running Microsoft Access 2000

12

Creating and using queries

Select Queries1. Switch to the Queries folder.

Creating and using queries

Select Queries2. Open a new query in Design View.

Page 13: Introduction of Running Microsoft Access 2000

13

Creating and using queries

Select Queries3. Choose the table(s) used to create the query.

Creating and using queries

Select Queries4. Select the display fields of the query and input the selection criteria.

Page 14: Introduction of Running Microsoft Access 2000

14

Creating and using queries

Select Queries5. Save the query.

Creating and using queries

Select Queries6. Double-click the query name or use Open to run the query.

Page 15: Introduction of Running Microsoft Access 2000

15

Creating and using queries

Action queriesUpdate QueryAppend QueryDelete QueryMake-Table Query

Example:Create an update query

Creating and using queries

Create an update query1. Create an select query with the criteria of the update query.

Page 16: Introduction of Running Microsoft Access 2000

16

Creating and using queries

Create an update query2. Convert the select query to update query.

Creating and using queries

Create an update query3. Specify how you want the data changed.

Page 17: Introduction of Running Microsoft Access 2000

17

Importing, linking and exporting data

ODBC (Open Database Connectivity)Create a new ODBC data source

ImportingLinkingExporting

ODBC

ODBC (Open Database Connectivity) is a SQL database interface developed by Microsoft. It allow one database product that “speaks” SQL be able to “talk” to other database product that understand SQL.

With ODBC, Microsoft Access can import (copy in) or link (connect to) data that is in text files, spreadsheets, other Access database, dBASE, Paradox, Microsoft FoxPro, and other SQL database that support ODBC. Microsoft Access can also export (copy out) data from Access tables to the databases, spreadsheets, Web pages, or test files of other application.

Page 18: Introduction of Running Microsoft Access 2000

18

Create a New ODBC Data Source

1. Open the control Panel, and click the 32bit ODBC.

Create a New ODBC Data Source

2. In the User DSN folder, choose Add… to add your new data source.

Page 19: Introduction of Running Microsoft Access 2000

19

Create a New ODBC Data Source

3. Select the driver for the new data source.

Create a New ODBC Data Source

4. Input the data source name and create the database.

Page 20: Introduction of Running Microsoft Access 2000

20

Create a New ODBC Data Source

5. A new user data source forCS485 is added.

Importing Data

Importing dBASE filesImporting Paradox filesImporting FoxPro filesImporting spreadsheet filesImporting text filesImporting Access objectsImporting SQL tables

Page 21: Introduction of Running Microsoft Access 2000

21

Importing Data

Importing dBASE files, Paradox files, FoxPro files1. Open the database to import the file.2. Choose the Get External Data from the File menu, then choose the Import submenu.

3. In Import dialog box, select the appropriate file type and file name.4. Click the Import button to import the file.5. Access responses with a message box that informs the result of the importing procedure (i.e., successfully imported ‘xxxxx’).6. Click the OK button to confirm the import procedure.

Importing Data

Importing spreadsheetSteps 1-4 are the same as previous one.5. An Import Spreadsheet Wizard dialog box is popped up. Simply follow the instruction of the wizard to finish specifying the detail of the table (i.e., choose whether first row contains column heading, select index and key, etc.).6. Access responses with a message box that informs the result of the importing procedure.7. Click the OK button to confirm the import procedure.

Page 22: Introduction of Running Microsoft Access 2000

22

Importing Data

Importing text filesSteps 1-4 are the same as previous one.5. An Import Text Wizard dialog box is popped up. Simply follow the instruction of the wizard to finish specifying the detail of the table (i.e., choose whether the data format is delimited or fixed width, whether first row contains column heading, to import to an existing table or a new table, etc.).6. Access responses with a message box that informs the result of the importing procedure.7. Click the OK button to confirm the import procedure.

Importing Data

Importing Access objectsSteps 1-4 are the same as previous one.5. An Import Objects dialog box is popped up. Choose the object to be imported and confirm the importing procedure.

Page 23: Introduction of Running Microsoft Access 2000

23

Importing Data

Importing SQL tables

Linking Data

Linking dBASE filesLinking Paradox filesLinking FoxPro filesLinking spreadsheet filesLinking text filesLinking Access objectsLinking SQL tables

Page 24: Introduction of Running Microsoft Access 2000

24

Importing vs. Linking

ImportingFile is relatively small.Data is not changed frequently by users of other database application.Data need not to be shared with other database application.Best performance is desired.

LinkingFile is large (i.e., larger than maximum capacity of local Access database [1 GB]).Data is changed frequently by users of other database application.Data need to be shared over network with other database applications.Performance does not matter.

Exporting Data

Exporting to dBASE fileExporting to Paradox filesExporting to FoxPro filesExporting to spreadsheet filesExporting to text filesExporting to Access objectsExporting to SQL tablesExporting to a web page

Page 25: Introduction of Running Microsoft Access 2000

25

SQL

In Microsoft Access, you can use SQL to:create tablesbuild select queriesbuild append queriesbuild delete queriesbuild update queries

SQL

1. Open a new query in design view.

Page 26: Introduction of Running Microsoft Access 2000

26

SQL

2. Close the Show Table Dialog box without adding any table.

SQL

3. Switch the query to SQL View.

Page 27: Introduction of Running Microsoft Access 2000

27

SQL

4. Write the SQL statement and save the query.

Using Forms

Forms are the primary interface between users and Microsoft Access application.

Using Forms in Microsoft Access, you can:Displaying and editing dataControlling application flowAccepting inputDisplaying messagePrinting information

Page 28: Introduction of Running Microsoft Access 2000

28

Using Forms

Building formsBuilding forms from scratchBuilding forms using Form WizardAdvanced form design

Building Forms from Scratch

1. Open a new form in Design View.

Page 29: Introduction of Running Microsoft Access 2000

29

Building Forms from Scratch

2. Use the tools in the Toolbox to set the layout of the form.

Building Forms from Scratch

3. Add the command buttons.

Page 30: Introduction of Running Microsoft Access 2000

30

Building Forms from Scratch

4. Set the properties of the controls (i.e., specify the event procedure of On Click for the Search button) and save the form.

Building Forms using Form Wizard

1. Open a new form using Form Wizard.

Page 31: Introduction of Running Microsoft Access 2000

31

Building Forms using Form Wizard

2. Select the fields to be displayed on the form.

Building Forms using Form Wizard

2. Follow the instructions to select the layout (i.e., Columnar) and style (i.e., Stone) of the form.3. Specify the name and save the form.

Page 32: Introduction of Running Microsoft Access 2000

32

Advanced Form Design

Basing a form on a multiple-tables queryCreating Multiple-page formsCreating and embedding subformLinking forms with a command button

Example: a simple search on Course and Faculty tables⌧A main form (search) used to input the search condition.⌧A second form (results) used to display the the result of the

search.

Advanced Form Design

1. Create a query (used for the results form) based on the course and faculty tables.

Page 33: Introduction of Running Microsoft Access 2000

33

Advanced Form Design

2. Create a new form as the results form, specify the query created in step 1 as the data source of the form.

Advanced Form Design

3. Set the layout of the form.

Page 34: Introduction of Running Microsoft Access 2000

34

Advanced Form Design

4. Set the properties of the form and controls, and save the from.

Advanced Form Design

5. Build the main form (refer to Building Forms from Scratch).

Page 35: Introduction of Running Microsoft Access 2000

35

Advanced Form Design

6. Write the event procedure for the Search and Close button.Search

/* check input and form the search condition */If Not IsNothing(Me!FID) Then

searchCondition = " FID = " & Me!FID… …/* open the subform results with the desired search condition */DoCmd.OpenForm FormName:="results", whereCondition:=searchCondition… ...

CloseDoCmd.Close

Advanced Form Design

7. Save the main form and run it.

Page 36: Introduction of Running Microsoft Access 2000

36

Advanced Form Design

8. The form results is shown after click the Search button.

Creating an Application

MacrosCreating MacrosAutomating applications with Macros

VBA (Visual Basic Application)Visual Basic in MS AccessAutomating applications with Visual Basic

Page 37: Introduction of Running Microsoft Access 2000

37

Macros

Using macros in MS Access, you can:Open any table, query, form, or report in any available view.Rename any objects in the database.Execute other macros or VBA functions.Emulate keyboard actions and supply input to system dialog boxes.Execute any command on any Access menu.Display informative message or sound a beep to draw attention.Send the data from a table, query, form or report to an output file.… ...

Creating Macros

1. Switch to the Macros folder.

Page 38: Introduction of Running Microsoft Access 2000

38

Creating Macros

2. Open a new Macro.

Creating Macros

3. Select the Action, and input the Condition and Comment. Input or choose the Action Arguments, and save the macro.

Page 39: Introduction of Running Microsoft Access 2000

39

Creating Macros

4. Run the macro.

Automating Applications with Macros

Example: A database startup routineDisplay a Welcome message when the database application start up.Next open a form that used to display course information of CS department.Display the information of course cs485 as default view.

Page 40: Introduction of Running Microsoft Access 2000

40

Automating Applications with Macros

Example: A database startup routine1. Create a new macro.

Automating Applications with Macros

Example: A database startup routine2. Specify the actions of the startup routine.

Page 41: Introduction of Running Microsoft Access 2000

41

Automating Applications with Macros

Example: A database startup routine3. Save the macro as Autoexec.

Automating Applications with Macros

Example: A database startup routine4. Open the database that contains the macro Autoexec.

Page 42: Introduction of Running Microsoft Access 2000

42

Visual Basic in MS Access

ModulesModule ObjectsForms or Report Modules

VBA Debug ToolsSetting BreakpointsUsing Debug Window

Collections and Objects

Modules

Module Objects

Page 43: Introduction of Running Microsoft Access 2000

43

Modules

Forms or Report Modules

VBA Debug Tools

Setting Breakpoints

Page 44: Introduction of Running Microsoft Access 2000

44

VBA Debug Tools

Using Debug Window

Collections and Objects

CollectionsForms Collection, Reports Collection, Modules Collection

ObjectsForms, Reports, Module⌧Forms![search]

Controls⌧Me![FID]

DoCmd, Screen⌧DoCmd.OpenForm FormName:="results", whereCondition:=searchCondition

Database, RecordSet⌧Dim db As Database | Set db = CurrentDb() ⌧Dim rcds As RecordSet | Set rcds = db.OpenRecordSet(“queryName”)

Page 45: Introduction of Running Microsoft Access 2000

45

Automating applications with Visual Basic

Example: A public function that checks user inputs of a form

Function IsNothing(v As Variant) As IntegerIsNothing = TrueSelect Case VarType(v)

Case vbEmptyExit Function

Case vbNullExit Function

Case vbBooleanIf varToTest Then IsNothing = False

Case vbByte, vbInteger, vbLong, vbSingle, vbDouble, vbCurrencyIf v <> 0 Then IsNothing = False

Case vbDateIsNothing = False

Case vbStringIf (Len(v) <> 0 And v <> " ") Then IsNothing = False

End SelectEnd Function

Automating applications with Visual Basic

Example: Get search conditions from user input

Page 46: Introduction of Running Microsoft Access 2000

46

Automating applications with Visual Basic

Example: Use SQL query to check result before display the form

Macros vs. VBA

MacrosDon’t need to trap errorsApplication consists of only a few forms.Defining alternative actions for certain keystrokes.Creating a startup routine that runs when the database opens.

VBANeed to discrete error handling.Define new functions.Handle events that pass parameters or accept return values.Create new objects (tables, queries, forms…) from application codeDirectly call Windows API functions.Manipulate data in a recordset on a record-by-record basis.