Here is an example for you. The first sub calls the function IsRecord. The result is passed back in the IsRecord function. Hope this helps.
Private Sub Event_ID_BeforeUpdate(Cancel As Integer)
Dim CheckExistingRecord As Boolean
'HERE IS THE EXAMPLE
CheckExistingRecord = IsRecord(Me!Event_ID, Me!Contact_ID)
If CheckExistingRecord = True Then
Me.Undo
DoCmd.Close acForm, "Attendance"
Exit Sub
End If
End Sub
Function IsRecord(intEvent_ID As Integer, intContact_ID As Long)
'look thru the recordset to verify if a record exists
On Error GoTo Err_IsRecord
Dim dbs As Database
Dim rst As Recordset
Dim strCriteria As String
Set dbs = CurrentDb
Set rst = CurrentDb.OpenRecordset("Event", dbOpenDynaset)
DoCmd.Hourglass False
With rst
strCriteria = "[Event_ID] = " & intEvent_ID & " And [Contact_ID] = " & intContact_ID
With rst
.MoveFirst
.FindFirst strCriteria
If .NoMatch = True Then
IsRecord = False
Else
MsgBox "A previous record has been found!"
'RETURN THE PARAMETER BACK TO THE CALLING PROCEDURE HERE.
IsRecord = True
End If
.Close
End With
Exit_IsRecord:
DoCmd.Hourglass False
Exit Function
Err_IsRecord:
Resume Exit_IsRecord
End Function