Here is my new code on the Forms BeforeUpdate event:
Private Sub Form_BeforeUpdate(Cancel As Integer)
'This verifies that a valid value is entered in the PK (txtMark)
On Error GoTo Err_Form_BeforeUpdate
Dim bytChoice As Byte
Dim newMark As String
If IsNull(Me.txtMark) Then
bytChoice = MsgBox("You failed to enter a valid door mark." & vbCrLf & _
"Please enter a valid door mark.", vbCritical + vbOKCancel, _
"Missing Door Mark")
If bytChoice = vbOK Then
GoTo NewMark_Form_BeforeUpdate
Else
DoCmd.RunCommand acCmdUndo
Me.txtMark.SetFocus
Exit Sub
End If
End If
NewMark_Form_BeforeUpdate:
newMark = InputBox("Please enter a valid door mark.", "Missing Door Mark")
Me.txtMark = newMark
Exit_Form_BeforeUpdate:
Exit Sub
Err_Form_BeforeUpdate:
If Err.Number = 3022 Then
MsgBox "The door mark you have entered has already been used." & vbCrLf & _
"Please enter a unique door mark.", vbCritical + vbOKOnly, "Duplicate Door Mark"
Resume NewMark_Form_BeforeUpdate
End If
MsgBox Err.Description, , "Error Number:" & Err.Number
Resume Exit_Form_BeforeUpdate
End Sub
Here is my new problem.
It works just like I wanted with the following exception:
If I cancel out of the first error (advancing to the next control), I enter a value for that field, attempt to update (resulting in the msgbox that I left the txtMark control blank), click vbOK (resulting in an input box for the newMark), I have the following results:
If I enter a unique value, the form works properly, the record is saved and all is merry & bright.
If I enter a duplicate value via the imput box, I get the following error:
The changes that you requested were not successful because they would create duplicate values in the index, pk, or the relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to allow duplicate entries and try again.
I would also like to trap this error. Where is this occurring?
Thanks for your help