Not sure if it's the copy/paste or if what you've posted is the actual code,
but, assuming the latter, you don't have a space between the _ character and
cboHireDate on the first line. This is different from what you'd posted
initially where it appeared that the cboHireDate started a new line?
Also, you state that Aircraft is a text field. That means that you need to
delimit the value coming from cboAircraft with ' marks in the first part of
the criteria string.
Thus, try this (note that I started new line for cboHireDate and that I've
put ' character on either side of cboAircraft concatenation):
If IsNull(DLookup("[Aircraft]", "BookingForm", "([Aircraft] = '" &
cboAircraft & "' AND [HireDate] = #" & _
cboHireDate & "#) AND ((#" & cboStartTime & "# BETWEEN [StartTime] AND
[EndTime]) OR (#" & _
cboEndTime & "# BETWEEN [StartTime] AND [EndTime]))")) Then
--
Ken Snell
<MS ACCESS MVP>
Cam said:
Here is the code as it is on my button - all names are as here
cboAircraft & " AND [HireDate] = #" & _cboHireDate & "#) AND ((#" &
cboStartTime & "# BETWEEN [StartTime] AND [EndTime]) OR (#" & _
cboEndTime & "# BETWEEN [StartTime] AND [EndTime]))")) Then
txtConfirm.Text = "Your booking is confirmed" ' Dlookup returns Null = No record found
Else
txtConfirm.Text = "Please Choose another Aircraft, Date, Time" 'DLookup found a record.
End If
End Sub
-------------------------------------------------------
Here are the fields from my table [BookingDetails]:
Timesheet ID (primary Key) = Autonumber
HireName = Number
Aircraft = Text
HireDate = Date/Time (formatted short date)
StartTime = Date/Time (formatted short time)
EndTime = Date/Time (formatted short time)
------------------------------------------------------
I have 2 additional tables a MembersDetails and an AircraftDetails. I also have a BookingQuery set up.
What I am trying to achieve is that once the user presses the confirm
booking button then the code checks the fields [Aircraft], [HireDate],
[StartTime] and [EndIte] to see if there is any duplication.
If there is duplication you get one message (Not Null) in a text box and
if there is duplication (Null) then you get another message. [i may remove
this and have a message bos instead - not decided yet)