surfbum3000
Technical User
I have a simple phonebook database which includes tblPhonebook and frmAdd. I am trying to prevent erroneous data from being entered. I set the validation rule for the PhoneNumber field in tblPhonebook to
Like "(281)*" Or Like "(713)*" Or Like "(800)*" Or Like "(832)*" Or Like "(903)*"
Validation Text: "You Have Entered An Invalid Phone Number"
When testing, I enter a fake number such as 888-888-8888. I get the Validation Text message. Click OK. So far so good. A second error then appears "The value in the record or field violates the validation rule for the record or field". Click OK. (I don't need this error message to appear since I have already notified the user with the previous message.) I am then returned to the phone number field. I change the phone number to a valid number. Then click Add Record (command button) which produces another window "Do you want to add this record?" Click OK. Then I get "You can't go to the specified record".
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctl As Control
On Error GoTo Err_BeforeUpdate
If Me.Dirty Then
If MsgBox("Do you want to add this new staff?", vbYesNo + vbQuestion, _
"Save Record") = vbNo Then
Me.undo
End If
End If
Exit_BeforeUpdate:
Exit Sub
Err_BeforeUpdate:
MsgBox Err.Number & " " & Err.Description
Resume Exit_BeforeUpdate
End Sub
Like "(281)*" Or Like "(713)*" Or Like "(800)*" Or Like "(832)*" Or Like "(903)*"
Validation Text: "You Have Entered An Invalid Phone Number"
When testing, I enter a fake number such as 888-888-8888. I get the Validation Text message. Click OK. So far so good. A second error then appears "The value in the record or field violates the validation rule for the record or field". Click OK. (I don't need this error message to appear since I have already notified the user with the previous message.) I am then returned to the phone number field. I change the phone number to a valid number. Then click Add Record (command button) which produces another window "Do you want to add this record?" Click OK. Then I get "You can't go to the specified record".
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctl As Control
On Error GoTo Err_BeforeUpdate
If Me.Dirty Then
If MsgBox("Do you want to add this new staff?", vbYesNo + vbQuestion, _
"Save Record") = vbNo Then
Me.undo
End If
End If
Exit_BeforeUpdate:
Exit Sub
Err_BeforeUpdate:
MsgBox Err.Number & " " & Err.Description
Resume Exit_BeforeUpdate
End Sub