Syntax in a FindFirst

JuniorWoodchuck24

Registered User.
Local time
Today, 15:36
Joined
Jan 13, 2010
Messages
59
I'm trying to load data that I have stored in a file and bring it into a form. The data was imported from excel and then I'm going to edit it within a from. I'm trying to use the FindFirst function to track an item down by it's Product Number.

I have a load button that does OnClick event with following code

Dim xtxtProductNumber
Dim db As Database
Dim rs As Recordset

xtxtProductNumber = Me![txtProductNumber]

Set db = CurrentDb()
Set rs = db.OpenRecordset("Products", dbOpenDynaset)
rs.FindFirst "ProductNumber = 'xtxtProductNumber' "

My error at the moment is that it is just returning the first item in the table and it doesn't matter what the product number is.
 
rs.FindFirst "ProductNumber = 'xtxtProductNumber' "

Should read

rs.FindFirst "ProductNumber = '" & xtxtProductNumber & "'"

David
 
is productnumber a number, or text

you ought to get in the habit of typing variables

so either

Dim xtxtProductNumber as string OR
Dim xtxtProductNumber as long

whichever is appropriate

the syntax of the findfirst is different in each case

foir single reads, you may find dlookup is easier to use then opening recordsets
 

Users who are viewing this thread

Back
Top Bottom