DLookup With Multiple Criteria

Learn2010

Registered User.
Local time
Today, 14:13
Joined
Sep 15, 2010
Messages
415
I have a form, frmLog, that requires a date, start time, and end time for meetings. The record source for the form is tblLogHold. I am trying to prevent duplicates in tblLog. Here are the fields involved:

DateOfMeeting, StartTime, DupeDateOfMeeting

I want the DupeDateOfMeeting to equal the DateOfMeeting if there is already a record in tblLog with the same DateOfMeeting and the same StartTime.

Here is what I have in the control StartTime.AfterUpdate.

Start Of Code
DupeDateOfMeeting = DLookup("DateOfMeeting", "tblLog", "[DateOfMeeting] =" & frmLog.DateOfMeeting And "[StartTime] =" & frmLog.StartTime)
End Of Code

I am getting a Visual Basic error message:

Run-time error "424':

Object required

Any ideas to help?

Thank you.
 
Start Of Code
DupeDateOfMeeting = DLookup("DateOfMeeting", "tblLog", "[DateOfMeeting] =" & frmLog.DateOfMeeting And "[StartTime] =" & frmLog.StartTime)
End Of Code
Code:
DupeDateOfMeeting = DLookup("DateOfMeeting", "tblLog", "[DateOfMeeting]  =" & frmLog.DateOfMeeting [COLOR=Red]& " AND[/COLOR] [StartTime] =" &  frmLog.StartTime)

One tip I have when you're working with SQL or SQL-like strings is to save them in a variable such as strSQL. Then include a debug.print for the variable once you've populated it. This allows you to see what you are actually passing for your statement. Of course, that assumes you have the proper syntax for the VBA part, which 'And' is not.
 
I'm not that knowledgeable with SQL. I tried different variations with your code and they didn't work. Can you try again?
 
DupeDateOfMeeting = DLookup("DateOfMeeting", "tblLog", "[DateOfMeeting] =" & frmLog.DateOfMeeting And "[StartTime] =" & frmLog.StartTime)

Perhaps...

If [DateOfMeeting] and [StartTime] are text boxes in some date format:

..., "[DateOfMeeting] = #" & frmLog![DateOfMeeting] & "# AND [StartTime] = #" & frmLog![StartTime] & "#")

Just a thought.
 

Users who are viewing this thread

Back
Top Bottom