Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Syntax of DAO Findfirst Function 1

Status
Not open for further replies.

xweyer

MIS
Sep 7, 2000
140
0
0
US

I'm having a problem getting the syntax right using the Right function with a variable in a DAO recordset using the FindFirst function.

Here's the relevant lines of code. The field [Sn_Scan] is text

Dim intSnGuessLen As Integer

(1st Version)
rst.FindFirst "Right([Sn_Scan],6) ='" & strGuessSN & "'"

(Needed Version)
rst.FindFirst "Right([Sn_Scan],intSnGuessLen) ='" & strGuessSN & "'"

When I hard code the value of intSnGuessLen (i.e. 6) directly as in the 1st Version of the line it works perfectly however I need the function to dynamically plug in the value of intSnGuessLen and can not get the syntax right.

The error I get with the needed version is "microsoft jet database engine does not recognize "intSnGuessLen" as a valid field or expression

Can someone help me with the syntax?


 
How are ya xweyer . . .

If [blue]Sn_Scan[/blue] is a field in the recordset then it should be:

Code:
[blue]rst.FindFirst "Right([purple][b]rst![/b][/purple]Sn_Scan, intSnGuessLen) ='" & strGuessSN & "'"[/blue]

You may want to check the [blue]NoMatch[/blue] property to tell if a record was found!

[blue]Your Thoughts! ...[/blue]


See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
rst.FindFirst "Right([Sn_Scan]," & intSnGuessLen & ")='" & strGuessSN & "'"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top