Jerry Post Copyright © 1998 1 Database Management Systems Chapter 8 Applications.

57
1 Jerry Post Copyright © 1998 Database Management Database Management Systems Systems Chapter 8 Applications

Transcript of Jerry Post Copyright © 1998 1 Database Management Systems Chapter 8 Applications.

1

Jerry PostCopyright © 1998

Database Management Database Management SystemsSystems

Chapter 8

Applications

2

DDAATTAABBAASSEE

Customer ReportFile Edit Help File Edit Help

Application Features

Application organization Menu Toolbar Help Transactions Improving forms Customized reports Distributing Applications

Sales Report

File Edit Help File Edit Help

SwitchboardSwitchboard

3

DDAATTAABBAASSEE

Application Design

Customer Form Order Form Bad design:

Enter data twice.

Poor design: Memorize data (ID) on one

form to enter on second.

Better design: Automatically transfer data

across forms.

Customer1592Jane Doe333 Elm St.

OrderCustomer:1592 Jane Doe333 Elm St.

4

DDAATTAABBAASSEE

Application Importance

User interface Make users’ jobs easier. Tie input forms and reports. Automate basic tasks Tie to external data

collection devices. Help system.

Ensure data integrity Validate data. Perform computations. Verify totals. Control user access. Maintain related

transactions. Backup and recovery.

Decision Support Monitoring of events. Analysis, Graphs, Reports. Statistical analysis and

optimization. Forecasts and simulation. Linking to other software.

Expert Systems & Intelligence Logic and forward chaining. Analysis and decisions in

code. Databases of cases,

situations and solutions.

5

DDAATTAABBAASSEE

PurchaseItem Quantity3876 10

SaleItem Quantity3876 1

Automated Inventory

Inventory table holds quantity-on-hand (QOH).

Sale subtracts items from QOH. Purchase adds items to QOH. Need a separate routine to

validate the current total.

InventoryItem Description QOH3876 Saddle 7

616

subtract add

6

DDAATTAABBAASSEE

Application Organization Organized by user needs.

Identify user. Outline tasks. Organize forms and reports.

Direct users to tasks. Potential drawbacks

Too many layers makes it difficult for users to find anything.

Poor organization confuses users and requires additional support and training.

Build forms and reports. Start with a core concept.

Identify most important features. Get them correct.

Add features, forms and reports. Issue application updates--number and date!

Use menu stubs for incomplete and future work. Make them invisible to the

user with the Visible property.

Be sure they are disabled.

7

DDAATTAABBAASSEE

User Orientation

Database application is a model of the organization. Applications based on user jobs. Flexibility and user control.

Application organization User tasks. User control over sequence.

Forms Minimize user entry. Anticipation.

Reports Easy access from forms. User selection of scope and

conditions or filters.

8

DDAATTAABBAASSEE

Initial Menu / Switchboard

Starting point for users. Identify the user.

From network if possible. Separate log in if needed.

Customized for users. Hide restricted options. Different forms as needed.

Avoid cluttered screens. Use graphics and color to

enhance the presentation. Limit the number of options.

9

DDAATTAABBAASSEE

Switchboard Uses

Acts as a directory for the application. Identifies users. Contains startup and shutdown code.

Can preload forms in background. Make them invisible. Speed up later usage.

Can initiate transaction and security logs. Can establish network connections.

Contains copyright and usage notes.

10

DDAATTAABBAASSEE

Sally’s Pet Store: Poor Organization

OrderMerchandise

Item

ReceiveMerchandise

Item

SellMerchandise

Item

GetCustomer

Data

What is wrong?

Focus needs to be at higher level (Order, Receipt, Sale); not Item.A

You cannot go from Order to Receipt.

You cannot go from Receipt to Sale.

You need to get customer data before recording the sale.

11

DDAATTAABBAASSEE

Sally’s Pet Store: Better Organization

Orders Receipt

Sale

Supplier

Customer

InventoryItems

specialorders

More links--usually as buttons.

Separate sales from orders, except for special orders.

12

DDAATTAABBAASSEE

Sally’s Pet Store: Initial VTOC

Sales

Animals

Customers

Suppliers

Purchase Merchandise

Sale Animal

Sale Merchandise

Customer Receipts

Supplier Payments

Animal Health

Animal Genealogy

Purchase Animals

Accounting

Marketing

Employees

Sales Report

Cash Flow

Accounts Payable

Accounts Receivable

Inventory

13

DDAATTAABBAASSEE

Menus Why a custom menu?

Limit user actions. Simplify user interface. Add custom actions. Menus can be activated by

keystrokes.AccessibilityTouch-typists and

heads-down data entry. Sometimes need different

menus for each form.

File Help

Contents

SearchAbout Rolling Thunder

File HelpEdit

Add Customer

Delete Customer Ctrl+DModify Customer Data

14

DDAATTAABBAASSEE

Creating Menus

View | Toolbars | Customize Drag and Drop

Multilevel menu.Sublevels/hierarchy.Each level is a separate menu with its

own name.

Menu choicesEach entry has a name.Access key: & (e.g., &File).Status Bar Text

ActionsSubmenu.Run any code.

15

DDAATTAABBAASSEE

Toolbars

Why toolbars? Single click for complex

actions. Commands available across

the application / shortcuts. Position and customization

by user.

Toolbar components Button

Text Icon/graphic (bitmap)

Tool Tip Status Bar description Action

Print

·Identify report

·Ask for single or multiple pages.

·Preview or print.SwitchboardSwitchboard

Weekly Sales AnalysisBuild graphsPrint reportsExport data to spreadsheet

16

DDAATTAABBAASSEE

Creating Toolbars View | Toolbars | New Customizing

Add new button.Select from DBMS list.Bring up query/form/report.Run code.

Change icon.Modify existing icon.Replace icon.Create your own icon and paste it on the button.Place text label on button.

Tool tips are vital. Status bar for description.

17

DDAATTAABBAASSEE

Icons

16 by 16 pixels 16 colors

Bright and shaded Dither to mix colors

Outline in black

18

DDAATTAABBAASSEE

Activating Toolbars and Menus

Install a menu Form: Attach a bar using

the form properties. Code

On ActivateOn Deactivate

Modify from code Add or remove options Enable/Disable (dim)

With myBar .Controls.Add Type:=msoControlButton, Id:=3 .Controls(1).Enabled = False .Controls.Add Type:=msoControlButton, Id:=3End WithmyBar.Visible = True

Set myBar = CommandBars(”Custom1")If user = ”Clerk" Then

myBar.Visible = TrueElse

CommandBars(”Database").ResetmyBar.Enabled = False

End If

19

DDAATTAABBAASSEE

Help

On-line help replaces manuals Context sensitive:

Pressing F1 key provides information on topic with current focus

Hypertext links to related topics Sequential topics

DescriptionsExamples

Definitions / Glossary Contents / overview Index / keywords Full-text search

Windows 95 & Win-NT

Sally’s Pet Store--ContentsCopyright NoticeThe Firm Introduction ProcessesEntering Data Sales Animal Health

Breeds (and other terms)

20

DDAATTAABBAASSEE

Help Structure

Help files are processed by Windows™. Write the help text.

Each topic on one page. Give it a unique TOPIC_NAME.

Give it a number. Enter the topic number in

the database.FormsControls

Create Help project file Map TOPIC_NAME to

number. Specify window sizes and

colors.

Use help compiler to build the help file.

Test the help system!

21

DDAATTAABBAASSEE

Writing the Help File Use a word processor that can

store a Rich Text Format (rtf) file.

Write a single topic on a page. Set unique TOPIC_NAME

specified in a footnote (#). Set a title for the topic in the

footnote ($). Choose key words for each

topic in footnote (K). Identify related topics in a

sequence, set by footnote (+): INTRODUCTION:001

Topics Written in any order. Keep a separate list for your

own use later. No spaces in topic names.

Build links to other topics. Double underline the displayed

word. (C-S-d) Type TOPIC_NAME

immediately after and make it hidden. (C-S-h)

Definitions/glossary words are marked with a single underline (C-u), followed by the TOPIC_NAME (C-S-h).

Figures/Bitmaps: Use graphics package to

create, edit, set size and reduce to 16 colors.

{bml filename.bmp} (Left align) {bmr filename.bmp} (Right)

22

DDAATTAABBAASSEE

Sample Help Page#$K+ Sally’s Pet Store Help Contents

The Contents section lists the primary topics available in Help. Point to a topic, then click themouse button.

Copyright Notice

The FirmIntroductionProcessesEmployees

Entering DataSalesAnimal HealthAnimal GenealogyPurchase OrdersReceive Shipments

Financial TransactionsCustomersManufacturers/SuppliersEmployees

# CONTENTS$ Pet Store ContentsK Contents; Sales; Animal:Health; Animal:Genealogy; Purchase; Receive; Introduction+ introduction:001

Double Underline: Link text Ctrl+Shift+DHidden text: Link name Ctrl+Shift+H

23

DDAATTAABBAASSEE

Sample Help Project (HCW)

MAP

Each topic name must be given a number.

Files

The name of the rtf help file.

24

DDAATTAABBAASSEE

Help Project File (.HPJ) [OPTIONS]

Basic setup. title= “Main title/caption” contents = TOPIC_NAME

[FILES] Specifies all files used. myhelp.rtf graphics files, etc.

[MAP] Maps names to numbers. TOPIC_NAME ####

[WINDOWS] Sets windows sizes.

[CONFIG] Sets macros and buttons.

Major sections: OPTIONS FILES MAP WINDOWS CONFIG

25

DDAATTAABBAASSEE

Context-Sensitive HelpSet the help file name in the form properties.

Set the topic number (Context Id) for each form or control.

26

DDAATTAABBAASSEE

Transactions Some transactions result in multiple

changes. These changes must all be

completed successfully, or the group must fail.

Protection for hardware and communication failures.

example: bank customer transfers money from savings account to checking account.

Decrease savings balance Increase checking balance Problem if one transaction and

machine crashes.

Possibly: give users a chance to reverse/undo a transaction.

Performance gain by executing transactions as a block.

Savings Accounts

Inez: 5340.924340.92

Checking Accounts

Inez: 1424.27

Transaction1. Subtract $1000 from savings.

(machine crashes)2. Add $1000 to Checking.

(money disappears)

$1000

27

DDAATTAABBAASSEE

Defining Transactions The computer needs to be

told which changes must be grouped into a transaction. Turn on transaction

processing. Signify a transaction start. Signify the end.

Success: save all changes Failure: cancel all changes

Usually set inside code in a form.

Microsoft Access workspace.BeginTrans workspace.CommitTrans workspace.Rollback

Dim wsp As Workspace, dbs As Database, rst As Recordset

Set wsp = DBEngine.Workspaces(0)Set dbs = CurrentDbSet rst = dbs.OpenRecordset(. . .)

wsp.BeginTrans

DoCmd.RunSQL “UPDATE Savings… ”DoCmd.RunSQL “UPDATE Checking… “

If (MsgBox("Save all changes?", vbQuestion + vbYesNo, " Save Changes") = vbYes) Then

wsp.CommitTransElse

wsp.RollbackEnd If

28

DDAATTAABBAASSEE

Transaction Locks Pessimistic locks

Recordset.LockEdits = True Locked from Edit to Update

Optimistic locks Recordset.LockEdits = False Compares data between Edit and

Update. Used for all external/ODBC.

Optimistic: if data has changed, generates error #3197.

Pessimistic: Edit can trigger an error if table is already locked by another user.

Let users retry update. Unless you need code fully

automatic Then consider random wait.

Error Handling for UpdatesOn Error Goto lblError

rst.Edit ‘ sample partial code rst!Column = Value rst.Update

lblExit: Exit SublblError: If (MsgBox(Err.Description, _

vbRetryCancel, “Error . . .”) _= vbRetry) Then

Resume Else ‘ Clean up changes wsp.Rollback ‘ If transactions set Resume lblExit End IfEnd Sub

29

DDAATTAABBAASSEE

Improving Forms

Combo Boxes Restricting with WHERE. NotInList to add data.

Make it easy for user Click for autoentry. Advanced lookup. Print options.

Decision Support Statistical analysis Optimization Simulation

Adding Expert System features Automatically compute

values. Guide user by asking

questions and suggesting answers.

Intelligence/logic in code.

30

DDAATTAABBAASSEE

Form Events (Some)

Open, Close Load, Unload Activate, Deactivate, Got Focus, Lost Focus Delete, Before Delete Confirm, After Delete Confirm Before Update, After Update Before Insert, After Insert Current (Change row) Click, Double Click Mouse Down, Mouse Move, Mouse Up Key Press, Key Down, Key Up Timer

31

DDAATTAABBAASSEE

1) Open 2) Load 3) Resize 4) Activate 5) Current

1233b

a

d

6) Enter

1233b

a

d

7) GotFocus

1233b

a

d

5) Close 4) Deactivate 3) Unload 2) LostFocus

1233b

a

d

1) Exit

1233b

a

d

ControlsForms

Change rows

Event Sequences (Form)

Close a Form

Open a Form

32

DDAATTAABBAASSEE

1) BeforeUpdate 2) AfterUpdate 3) Exit 4) LostFocus

5) Enter 6) GotFocus

New data

Check it.

Saved data

Update others.

New control New control

Event Sequences (Enter Data) User enters data & focus moves to new control.

Difference between Exit and LostFocus If user clicks a different form, then clicks back. LostFocus and GotFocus events will trigger, but not Exit/Enter.

33

DDAATTAABBAASSEE

Triggers and Conditional Changes Enter

Can save current value before it is changed.

Before Update Test new value before saving it. Verify that user wants to make

change. If possible, use database

criteria instead.

After Update Make changes to other data. Use transactions to ensure all

changes are completed.

General : DeclarationsDim varOld As VariantSub ctl_Enter varOld = ctlEnd SubSub ctl_Before Update If (MsgBox (“OK to change?” . . .) = vbNo) Then [ctl] = varOld End IfEndSub

32

32

131

131

131

131

Enter

GotFocus

Keystrokes

Exit

BeforeUpdate

AfterUpdate

time

control event

131 LostFocus

34

DDAATTAABBAASSEE

Automated Inventory Link Inventory/QOH to SaleItem

table on Sale subform query. QuantitySold control

On Enter varOld = Quantity If IsNull(varOld) Then varOld = 0 Defined in General : Declarations.

AfterUpdate QOH = QOH - (Quantity - varOld) varOld handles user corrections.

Need a separate program that verifies and corrects all totals. Allow managers to set QOH by hand. Run separately to correct errors. Security controls on usage.

Sales

Item Price Quantity QOH

112 24.99 2 143203 15.47 1 8

5

User enters initial value.

35

DDAATTAABBAASSEE

Automated Inventory Events

Item QOH QOH-Qty112 145112 143 = 145 - 2112 138 = 143 - 5

Inventory

Initial value.User enters sale of 2 items.User changes value to a 5.

Time

Event

DeclarationsDim varOld As Variant

On EntervarOld = QuantityIf IsNull(varOld) Then varOld = 0

AfterUpdateQOH = QOH - (Quantity - varOld)

Corrected code

36

DDAATTAABBAASSEE

Opening Forms for Related Data

Open a second form based on value in current form.

Print a report for current entry on a form.

CustomerCustomerID NameAddress

11

Lee Gentry

5744 High Street

Payments Customer PaymentsCustomerID 11

Date Amount2-15-98 $97.003-15-98 $97.00

Print

Customer BillNameAddressBalance DuePayments2-15-98 $973-15-98 $97

Sub Payments_Click() Dim stDocName As String Dim stLinkCriteria As String stDocName = "CustomerPayment" stLinkCriteria = "[CustomerID]=" & Me![CustomerID] DoCmd.OpenForm stDocName, , , stLinkCriteriaEnd Sub

37

DDAATTAABBAASSEE

Department Evaluation

Division

Department

Combo Boxes / Hierarchical Data

Many business situations use hierarchical relationships Divisions: Departments Category: Product

Data entry on a form User select higher level from

first combo box. For lower level, select from

list that is restricted to those in the higher level.

Add a WHERE clause to the lower level combo box SQL.

Force the new clause to requery when entry changes.

Finance

InvestmentsBudgetingCost Analysis

cboDivision

cboDivision: AfterUpdate

cboDepartment.Requery

cboDepartment.RowSource

SELECT DepartmentFROM DepartmentListWHERE DepartmentList.Division =

[cboDivision];

38

DDAATTAABBAASSEE

Combo Boxes / NotInList

Two ways to add to list. Separate button NotInList event

To user NotInList is easy. Be careful when adding

Give user chance to cancel. Don’t make user enter data

twice. Add data to all necessary

tables.

Set LimitToList = True.

Basic structure See if user wants to cancel. Open table, AddNew row. Copy new value. Open form at that value and

get additional data.

Potential problems Method might not be

obvious to user. Difficult to enter data with

matching key, e.g., phone number shared by two customers.

Might need button as well.

39

DDAATTAABBAASSEE

NotInList Code

Set dbs = CurrentDB()Set rst = dbs.OpenRecordset(“Customer”)Set ctl = Me!Customerctl.UndoIf (MsgBox("Do you wish to add a new Customer?", vbYesNo,

"Customer " & NewData & "is not in list yet.") = vbYes) Thenrst.AddNewrst!CustomerName = NewDatastrMatch = "[CustomerID] = " & rst!CustomerIDrst.UPDATEDoCmd.OpenForm ”Customer", , , strMatchrst.CloseResponse = acDataErrAdded

ElseResponse = acDataErrContinue

End If

41

DDAATTAABBAASSEE

Advanced Lookup Lists List of items Rolling Thunder Supplies

Click shows details. DblClick sets receive date. Button opens matching form to

change details. Sort buttons rebuild list query

ORDER BY clause.

DoCmd.GoToControl "PurchaseID"DoCmd.FindRecord [OrderList] ‘DisplaydataIf (DoUpdate = True) Then ‘Parameter If (IsNull([ReceiveDate])) Then [ReceiveDate] = Now ‘DblClick-set date SetQuantityReceived (Now) Else ‘If date set, DblClick means remove [ReceiveDate] = Null SetQuantityReceived (Null) End IfEnd IfForms![ReceiveSupplies].RefreshForms![ReceiveSupplies]![OrderList].Requery

42

DDAATTAABBAASSEE

' Global PrintWhereClause As String' Global PrintOptionResponse As Integer' It is called as follows:' PrintWhereClause = "CustomerID = " & [CustomerID]' DoCmd OpenForm "PrintOptions" "1Print the _____ report for " & CustomerName' The leading value is the default selection: 1=one record, 2=all records, 3=criteria' Select Case PrintOptionResponse' Case 1' DoCmd OpenReport "myReport", acViewPreview, , "Customer ID = " & [CustomerID]' Case 2' DoCmd OpenReport "myReport", acViewPreview' Case 3' DoCmd OpenReport "myReport", acViewPreview, , PrintWhereClause' Case Else' Do nothing' End Select' Be sure to have an ON ERROR section to catch bad where clauses set by users in option 3

Print Options Message Single Item Entire Set Page layout, . . . Selection Criteria

Criteria invisible until user picks 3

Message set by calling subroutine

43

DDAATTAABBAASSEE

Custom Reports

Limitations to report writers Limited computations Control over layout Format codes: SGML & HTML Conditional (data driven)

changes Color-codes based on data

(show negative as red). Data thresholds (over 100,000

different formula).

Hints for custom code Be careful with proportional

typefaces and graphics. Best to write to a standard file

format like RTF or EPS and print with a word processor.

44

DDAATTAABBAASSEE

Report Layout

Report FooterReport header

Page header

Group1 header

Group2 header

Detail

Group2 footer

Group1 footer

Page footer

Report footer

Customer PurchasesCustomer: Jones

Order 4748Item # Value11987 $ 198.7514847 $7462.83Total $7661.58

Order 5092Item# Value73632 $ 52.35Total $ 52.35

Customer Total$7713.93

Page 32

45

DDAATTAABBAASSEE

Report Coding Structure Report Header Loop

Test for top of page Test for top of group 1

Test for top of group 2 . ..

Perform calculations and subtotals

Print detail Increment line/position counters Test for page break Set all prior group values Read next row of data Test for end of groups

Last to first Print group footers

Report Footer

46

DDAATTAABBAASSEE

Report Coding

Define base query first. Write separate lookups if:

queries are not available. performance problems.

Pages Counter for page numbers. Line counter or position

measure, and page size.

Groups Accumulator for sum, avg. Counter for average. Prior value to test break.

50

DDAATTAABBAASSEE

Distributing an Access Application

Make the application standalone. Runs completely from your forms. Never need to use the Access database menu

(Tables, Queries, Forms, Reports). Automatically starts when the database is opened.

Tools | Database Utilities | Startup. AutoExec macro.

Application format. Standard mdb file. Encrypted mde file.

Run-time package (Developer’s Edition). Security (Chapter 10). Installation package (Developer’s Edition).

51

DDAATTAABBAASSEE

Appendix: VB Applications

VB Advantages Standalone application. Compiled code (speed). Easy to connect to multiple

databases. Support and control over

Windows resources. Easier than C++.

Drawbacks Requires more

programming than Access.

Building projects Design and create the data

tables. Design and prototype the

forms and application design.

Create skeleton VB forms (try the Application Wizard and Data Form Wizard).

Add features to make the application easier to use.

52

DDAATTAABBAASSEE

Appendix: VB Sales Form

Similar to AccessEase of Use features

53

DDAATTAABBAASSEE

Appendix: Sales Form Design

Data control

Combo box

dbGrid

54

DDAATTAABBAASSEE

Appendix: Data Control

1. Type of DBMS

2. Actual database

3. Query or Table

55

DDAATTAABBAASSEE

Appendix: Data Grid SubformSale

Animal

Data control for grid (invisible)datSecAnimal

Grid control

Data control for main formdatPrimaryRS

' restrict the grid’s data control query to match main form

strSQL = “SELECT … WHERE [SaleID] = " &datPrimaryRS.Recordset![SaleID]

datSecAnimal.RecordSource = strSQL' then refresh the control, which forces a redisplaydatSecAnimal.Refresh

Reposition Event for datPrimaryRS

56

DDAATTAABBAASSEE

Appendix: Adding Data to a Subform Grid

Private Sub grdAnimal_BeforeUpdate(Cancel As Integer) If Not IsNull(grdAnimal.Columns(1).Value) Then datSecAnimal.Recordset.Fields("SaleID").Value

= datPrimaryRS.Recordset.Fields("SaleID").Value Else Cancel = True End IfEnd Sub

Sale(SaleID, SaleDate, CustomerID, EmployeeID, SalesTax)

SaleAnimal(SaleID, AnimalID, SalePrice)

An animal is sold by adding a row to the SaleAnimal table in the Animal subform/grid.

Application code should automatically copy the current SaleID into the new row.

57

DDAATTAABBAASSEE

Appendix: VB Combo Boxes

3. Name of column to use (ID).

2. Name of column to display.

1. Data control to fill the list.

5. Name of column to receive value.

4. Data control to store choice.

SELECT CustomerID, [LastName] & ", " & [FirstName] AS CName,FROM CustomerORDER BY [LastName] & ", " & [FirstName].

58

DDAATTAABBAASSEE

Appendix: Adding New CustomersPrivate Sub cmdNewCustomer_Click() Dim v As Variant' Create new customer datCustomer.Recordset.AddNew v = datCustomer.Recordset.Fields("CustomerID") datCustomer.Recordset.Update' get CustomerID, and stick it in the primary/sales recordset datPrimaryRS.Recordset.Edit datPrimaryRS.Recordset.Fields("CustomerID") = v datPrimaryRS.Recordset.Update ' Since all the necessary data is on this form, just fill it out txtFields(8).SetFocus ' If you need, you can open the Customer form, in case there is more data 'frmCustomer.Show 'frmCustomer.SetFocus 'frmCustomer.datPrimaryRS.Recordset.FindNext "CustomerID=" & vEnd Sub

59

DDAATTAABBAASSEE

Appendix: Data Grid Combo Box

AnimalID Name Category … Animal grid (list animal being sold)

AnimalID grid: Invisible(list all animals available to sell)

1. Data control to list all animals available.

2. Data grid to display the animals, but start invisible.

3. Turn on the button property for the AnimalID column in the underlying Animal grid.

4. In the button_click event for the underlying Animal grid, make the new AnimalID grid visible.

5. When the clerk double-clicks a row in the AnimalID grid, transfer the selected AnimalID back to the SaleAnimal table.

60

DDAATTAABBAASSEE

Appendix: Grid Control Button Click

grdAnimal.Columns(1).Button = True

When you define the animal grid, turn on the combo box arrow (button) for the AnimalID column.

When the button is clicked, make the new AnimalID grid visible.

Private Sub grdAnimal_ButtonClick(ByVal ColIndex As Integer) If (ColIndex <> 1) Then Exit Sub datAnimal.RecordSource = "SELECT AnimalID, Category, Breed, …” datAnimal.Refresh grdAnimalID.Visible = True grdAnimalID.Columns("AnimalID").Width = 720 ' Reset to default values grdAnimalID.Columns("Category").Width = 945 ' in case user changed grdAnimalID.Columns("Breed").Width = 1545 ' them last time grdAnimalID.Columns("Name").Width = 1170 grdAnimalID.Columns("ListPrice").Width = 870 grdAnimal.Columns("ListPrice").NumberFormat = "#,##0.00" grdAnimalID.SetFocusEnd Sub

61

DDAATTAABBAASSEE

Appendix: Transfer Selection to Table

Private Sub grdAnimalID_DblClick() datSecAnimal.Recordset.Edit datSecAnimal.Recordset.Fields("AnimalID")

= datAnimal.Recordset.Fields("AnimalID") datSecAnimal.Recordset.Update varTotalAnimalSale ComputeTax datPrimaryRS.UpdateRecord grdAnimal.SetFocus ' Just to be safe grdAnimalID.Visible = FalseEnd Sub

Code is triggered by double-click event in the grdAnimalID.