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!

Can someone tell me what is wrong with this line of code PLEASE???

Status
Not open for further replies.

gogirl

MIS
Jun 5, 2002
46
0
0
US
rst.FindFirst "empFirstName = '" & strInput1 & "'" & "empLastName = '" & strInput2 & "'"

I continute to receive a syntax error.

Thanks!

Cara
 
Hi GoGirl,

Try this...

rst.FindFirst "empFirstName = '" & strInput1 & "'" & " AND empLastName = '" & strInput2 & "'"

 
I basically came up with the same thing:

Dim db As Database, rst As Recordset
Dim strCriteria As String
Dim strInput1 As String
Dim strInput2 As String

Set db = CurrentDb

strInput1 = "Wiley"
strInput2 = "Coyote"

strCriteria = "[CustomerFirstName] = '" & strInput1 & "'" & " And [CustomerLastName] = '" & strInput2 & "'"

Set rst = db.OpenRecordset("tbl Customers", dbOpenDynaset)
' Find first matching record.
rst.FindFirst strCriteria
' Check if record is found.

If rst.NoMatch Then
'do this
Else
'do that
End If
rst.Close
Set db = Nothing
 
Are you using Access 2000?

DAO or ADO?

ADO does not have findfirst method.
 
This example comes from Acc2K KnowledgeBase article

If ValidateKeyFields = True Then
varBHId = Me.cmbFind
'Find the record that matches the control
Me.RecordsetClone.FindFirst "[BatchNumber] = '" & varBHId & "'"
Me.Bookmark = Me.RecordsetClone.Bookmark
Me.cmbFind.Value = Null
Else
Me.cmbFind.Value = Null
Exit Sub
End If

You can also use it in Acc2K by using DAO

Private Sub FindFirst_Click()

Dim rst As DAO.Recordset
Dim strCriteria As String

Set rst = Me.RecordsetClone
rst.FindFirst "[CompanyName] = 'B''s Beverages'"

If rst.NoMatch Then
MsgBox "No match was found."

Else

Me.Bookmark = rst.Bookmark

End If
rst.Close

End Sub

 
cmmrfrds, I am using Access XP and DAO.

suntsu, thank you very much! Your solution worked.

evalesthy, thank you very much! Your solution also worked and your extra code was very helpful.

Thanks All!

Cara
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top