S
Steve
In a form BeforeUpdate event I'd like to check for missing data and duplicate
data and pass back custom messages. The code (below) for missing data works
fine but I'd like some guidance on what additional code is needed to check
for duplicate data. The four fields (Account_Number, Result, DateofService,
and TestID) are all set as primary keys.
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
'check to see that all data are filled in'
If IsNull(Me.Account_Number) Then
Cancel = True
strMsg = strMsg & "Account Number field required." & vbCrLf
End If
If IsNull(Me.Result) Then
Cancel = True
strMsg = strMsg & "Result field required." & vbCrLf
End If
If IsNull(Me.DateofService) Then
Cancel = True
strMsg = strMsg & "Date of Service field required." & vbCrLf
End If
If IsNull(Me.TestID) Then
Cancel = True
strMsg = strMsg & "Test ID field required." & vbCrLf
End If
'etc for other fields.
If Cancel Then
strMsg = strMsg & vbCrLf & "Complete the record, or press <Esc>
twice to undo."
MsgBox strMsg, vbExclamation, "Invalid record"
End If
End Sub
data and pass back custom messages. The code (below) for missing data works
fine but I'd like some guidance on what additional code is needed to check
for duplicate data. The four fields (Account_Number, Result, DateofService,
and TestID) are all set as primary keys.
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
'check to see that all data are filled in'
If IsNull(Me.Account_Number) Then
Cancel = True
strMsg = strMsg & "Account Number field required." & vbCrLf
End If
If IsNull(Me.Result) Then
Cancel = True
strMsg = strMsg & "Result field required." & vbCrLf
End If
If IsNull(Me.DateofService) Then
Cancel = True
strMsg = strMsg & "Date of Service field required." & vbCrLf
End If
If IsNull(Me.TestID) Then
Cancel = True
strMsg = strMsg & "Test ID field required." & vbCrLf
End If
'etc for other fields.
If Cancel Then
strMsg = strMsg & vbCrLf & "Complete the record, or press <Esc>
twice to undo."
MsgBox strMsg, vbExclamation, "Invalid record"
End If
End Sub