Access.2007.VBA.Bibl..

(John Hannent) #1
FIGURE 5.4

The default references for a new Access 2003 database.


When using one of the Find*search methods (FindFirst, FindNext, and so forth),
save the search string to a variable, and display it in the Immediate window using a
Debug.Printstatement; this will be very helpful in debugging any problems because it shows you
exactly what expression is being used for the search.

If you are working on a database originally created several Access versions ago, it might have
ambiguous declarations such as:

Dim dbs As Database
Dim rst As Recordset

As a demonstration of possible problems, the following procedure sets up a recordset and uses
FindFirstto locate the first match for “Microsoft” in the CompanyID field:

Private Sub TestFindFirst()

Dim dbs As Database
Dim rst As Recordset
Dim strSearch As String

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(Name:=”tblCompanyIDs”, _
Type:=dbOpenDynaset)
strSearch = “[CompanyID] = “ & Chr$(39) _
& “Microsoft” & Chr$(39)
Debug.Print “Search string: “ & strSearch
rst.FindFirst strSearch

End Sub

TIPTIP


Working with Access Data 5

Free download pdf