Private Sub txtStationRunNumber_BeforeUpdate(Cancel As Integer)
Dim rst As DAO.Recordset
Dim strStationRunNumber As String
Dim strCriteria As String
Dim lngBookmark As Long
I am using the following code to check if a value has already been entered. If so, I want to clear only that field. However, I get the error mismatch message and two fields get cleared out. All help is appreciated.
If Nz(Me.StationRunNumber, "") <> "" Then
strStationRunNumber = Me.StationRunNumber
Set rst = Me.RecordsetClone
strCriteria = "[StationRunNumber]='" & strStationRunNumber & "'"
lngBookmark = Nz(DLookup("StationRunNumber", "tblIncidents", strCriteria), 0)
If lngBookmark > 0 Then
Me.Undo
MsgBox "The Station Run Number of " & strStationRunNumber & " already exists in the database." & vbCrLf & vbCrLf & _
"Please re-enter the Station Run Number", vbInformation, "Duplicate Station Run Number " & strStationRunNumber
End If
rst.Close
Set rst = Nothing
End If
End Sub