Multiple Criteria

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Using a Findfirst to locate a record in a linked table. How do I set up the
criteria for three variables that are strings and one variable that is a
number:

I need the grammer of quotes, single quotes, and &s to complete this line of
code: rst.findfirst Job=mStr1 and Name=mStr2 and Place=mStr3 and ID=mNum1

Tried the KB article - same examples that have been in use since Access7.0 -
no help there. Thanks in advance.
 
Concatenate the values from your variables into the string you want to use
for FindFirst.

Delimit the values for the Text fields (but not the Number field) with
quotes.

This kind of thing:
Dim strWhere As String
strWhere = "(Job = """ & mStr1 & """) AND (Name = """ & mStr2 & _
""") AND (Place = """ & mStr3 & """) AND (ID = " & mNum1 & ")"
Debug.Print strWhere
rst.FindFirst strWhere

The Debug.Print dumps the string to the Immediate Window (Ctrl+G). You can
then see if it looks right. It must look just like the WHERE clause of a
query.

(Note that a field called Name is going to give you problems in many
contexts. Nearly everything in Access has a Name property: tables, fields,
forms, reports, controls, ..., and at some point Access will thing you mean
the name of something else instead of the contents of the field.)
 
Back
Top