My Function SEEK Method doesn't work

J

javierlara

I try to search School and Date. but my code doesn't work
Can you Tell me my error?
Appreciate your help.

'--------------------Beginning Code

Dim db1 As Database, tb1 As Recordset
Dim esvar As Variant

tb1.MoveFirst
With tb1
.Index = "school"
esvar = .Bookmark
.Seek "=", [School] & [Date]
If .NoMatch Then
MsgBox ("This School and Date not Found")
Else
MsgBox ("This School and Date found and You are need to
verification date")
Date.SetFocus
'Cancel.True
End If
tb1.Close
End With
 
J

John W. Vinson

I try to search School and Date. but my code doesn't work
Can you Tell me my error?
Appreciate your help.

'--------------------Beginning Code

Dim db1 As Database, tb1 As Recordset
Dim esvar As Variant

tb1.MoveFirst
With tb1
.Index = "school"
esvar = .Bookmark
.Seek "=", [School] & [Date]
If .NoMatch Then
MsgBox ("This School and Date not Found")
Else
MsgBox ("This School and Date found and You are need to
verification date")
Date.SetFocus
'Cancel.True
End If
tb1.Close
End With

You're searching the School index for a text string consisting of the school
and the date. Unless you have BOTH values stored in the index named School as
a concatenated text string, it won't find it!

Why not just use FindFirst? Unlike SEEK it will let you use a full, unbridled
SQL WHERE clause:

Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone ' recordset of the current form
rs.FindFirst "[School] = " & Me.[School] & " AND [Date] = #" & Me.[Date] & "#"
If rs.NoMatch Then
Msgbox "This School and Date Not Found"
Else
Me.Bookmark = rs.Bookmark ' display found record on form
End If
Set rs = Nothing

John W. Vinson [MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top