Private Function ErrorChecking() If Me.NewRecord = True Then Dim strCriteria As String strCriteria = "Address = " & Me.txtAddress & " And city = " & Me.txtcity & "" If DCount("ID", "CommissionEntry", strCriteria) > 0 Then MsgBox "Someone has already entered data for this address and city. Are you sure you want to proceed?" Me.Undo Me.txtAddress.SetFocus ErrorChecking = True End If End If End Function
Private Sub Form_BeforeUpdate(Cancel As Integer) If ErrorChecking = True Then Cancel = True Exit Sub End If End Sub
From novice to tech pro — start learning today.