Using Access 2000
On a form "frmAppointments", based on "tblDates", two fields are MyDate, bound to MyDate in the table, and cboEvent bound to EventID in the table.
What I want to do is check for duplicate entries on the same date that have the same EventID when the EventID is > 3.
Here is the code I have been working with on the AfterUpdate event of cboEvent...
This works if an event already exists on that date and has an EventID of 1, 2 or 3. However, if the EventID is greater than 3 the "possible duplicate message" appears if there is an event on any date in the table.
I also tried putting dteTemp and eventTemp together into a string, but this didn't work. I also tried declaring dteTemp as Variant rather than Date, but that didn't work.
I also tried replacing the DLookup functions with the following...
but this results in a runtime error 2342 (argument consisting of an SQL statement required)
Any suggestions as to how to make the procedure work?
Thanks.
Tom
On a form "frmAppointments", based on "tblDates", two fields are MyDate, bound to MyDate in the table, and cboEvent bound to EventID in the table.
What I want to do is check for duplicate entries on the same date that have the same EventID when the EventID is > 3.
Here is the code I have been working with on the AfterUpdate event of cboEvent...
Code:
Private Sub cboEvent_AfterUpdate()
Dim intAnswer As Integer
Dim dteTemp As Date
Dim eventTemp As Variant
dteTemp = DLookup("MyDate", "tblDates", "[MyDate] = " & "#" & Forms!frmAppointments!MyDate & "#")
eventTemp = DLookup("EventID", "tblDates", "[EventID] = Forms!frmAppointments!cboEvent And [EventID] > 3")
If Not IsNull(dteTemp) And Not IsNull(eventTemp) Then
intAnswer = MsgBox("You already have an entry for this event on this day." & vbCrLf & "" _
& " Is this a duplicate entry?" _
, vbYesNo Or vbExclamation Or vbDefaultButton1, "Possible Duplicate")
Select Case intAnswer
Case vbYes
Call MsgBox(" Thank you." _
& vbCrLf & "Entry will be cancelled." _
, vbExclamation Or vbDefaultButton1, "Duplicate entry")
Me.Undo
Me.MyDate.SetFocus
Case vbNo
Call MsgBox(" Thank you." _
& vbCrLf & "Continue with your entry." _
, vbExclamation Or vbDefaultButton1, "Entry process continuing")
End Select
End If
End Sub
This works if an event already exists on that date and has an EventID of 1, 2 or 3. However, if the EventID is greater than 3 the "possible duplicate message" appears if there is an event on any date in the table.
I also tried putting dteTemp and eventTemp together into a string, but this didn't work. I also tried declaring dteTemp as Variant rather than Date, but that didn't work.
I also tried replacing the DLookup functions with the following...
Code:
Dim strSQL As String
Dim strTemp As Variant
strSQL = "SELECT tblDates.MyDate, tblDates.EventID " _
& "FROM tblDates " _
& "WHERE (((tblDates.MyDate)=Forms!frmAppointments!cboEvent) AND ((tblDates.EventID)>3));"
DoCmd.RunSQL strSQL
strTemp = strSQL
Any suggestions as to how to make the procedure work?
Thanks.
Tom