Question : Checking for a duplicate combination before saving a new record

I have a entry form for a table - entering journeys.  I want to issue a warning if the combination of Passenger ID and the Journey date already exists.

I am looking at some code of the format:

Private Sub Date_AfterUpdate()
If DCount("*", "tblJourneys", "[Passenger ID]= Me.Passenger ID and [Date] = Me.Date") > 0 Then
    MsgBox ("Duplicate")
End If
   
but this always shows up a syntax error.  I have tried various combinations of syntax but with no real success.

I am sure this is relatively straightforward - hope someone can come up with some simple code for this.

Regards

Richard
End Sub

Answer : Checking for a duplicate combination before saving a new record

open form frmNewJourney in design view
change the name of the combo box for Passenger  from Field41 to cboPassengerID

use this codes

Private Sub Time_Enter()
If DCount("*", "tblJourneys", "[Passenger ID]= " & Me.cboPassengerID & " and [Date] = #" & Me.DTPicker6 & "#") > 0 Then
    MsgBox ("Duplicate")
   
End If

End Sub
Random Solutions  
 
programming4us programming4us