Dlookup - I can't see what is wrong?

fat controller

Slightly round the bend..
Local time
Today, 16:55
Joined
Apr 14, 2011
Messages
758
I have a DLookup that won't work, and I have no idea why;

Field name - ID (Primary key, autonumber)
Table name - tblQSI
Criteria - find the ID of the record that has a service date matching the date in unbound text box.

Code:
Dim DateChk
Dim varID
DateChk = Me.txtDateCheck.Value

varID = DLookup("ID", "tblQSI", "Service_Date=#" & DateChk & "#")
Now, I know that there is a record matching the date I put in, one because I have checked the table and there is only three test records in there at the moment, and two because it has been checked using DCount on a prior step on the form (it determines which of the controls become visible, and this code is for one of the controls that becomes visible), and the DCount line is pretty similar to the above
Code:
If DCount("Service_Date", "tblQSI", "Service_Date=#" & DateChk & "#") = 0 Then
The DCount works fine, but the DLookup is returning null?
 
Daft question but is ID the correct name for the field? Everything else looks okay.
 
Try:
DateChk = Format([txtDateCheck], "\#mm\/dd\/yyyy\#")
varID = DLookup("ID", "tblQSI", "Service_Date = " & DateChk)

Thank you sir! Now works a treat. :) I am getting better at this VBA lark, but there is still the occasional thing that catches me out

Daft question but is ID the correct name for the field? Everything else looks okay.

Yes - all working now :)
 

Users who are viewing this thread

Back
Top Bottom