I am attempting to build a little routing to prevent the entry of duplicate event records in my database.
Here is the code:
'------------------------------------------------------
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not (IsNull(DLookup("[From date]", "Events", "[Venue] = '" & [Forms]![Event entry]![Venue] & "'" & _
DoCmd.RunCommand acCmdUndo
End If
End Sub
'------------------------------------------------------------------------
As you can see from the 'Sub' it is to run prior to record update.
When it runs i get an error:
I think it is due to the dates, but am not sure.
Any help would be greatly appreciated.
TIA
Here is the code:
'------------------------------------------------------
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not (IsNull(DLookup("[From date]", "Events", "[Venue] = '" & [Forms]![Event entry]![Venue] & "'" & _
" and [From date] >= #" & [Forms]![Event entry]![From date] & "#" & _
" and [From date] <= #" & [Forms]![Event entry]![Thru date] & "#")) _
And IsNull(DLookup("[From date]", "Events", "[Venue] = '" & [Forms]![Event entry]![Venue] & "'" & _" and [From date] <= #" & [Forms]![Event entry]![Thru date] & "#")) _
" and [Thru date] >= #" & [Forms]![Event entry]![From date] & "#" & _
" and [Thru date] <= #" & [Forms]![Event entry]![Thru date] & "#"))) Then
MsgBox "The current event overlaps an existing event at this venue." & vbCrLf & vbCrLf & _" and [Thru date] <= #" & [Forms]![Event entry]![Thru date] & "#"))) Then
"This record will be undone.", vbCritical + vbOKOnly, "Event overlap!"
Cancel = True
DoCmd.RunCommand acCmdUndo
End If
'------------------------------------------------------------------------
As you can see from the 'Sub' it is to run prior to record update.
When it runs i get an error:
Run-time error '3464': Datatype mismatch in criteria expression.
The Venue field is stored as a foreign key and is a combo box bound to the foreign key. The dates are just that, dates.
I think it is due to the dates, but am not sure.
Any help would be greatly appreciated.
TIA