Prevent Combo Error

  • Thread starter Thread starter scott
  • Start date Start date
S

scott

I'm trying to prevent a user from leaving or tabbing past a combo box
control without selecting a value. If they don't select a value, they get
the referential integrity error below. My AfterUpdate code below won't catch
the error. I'd like to display a warning and then force focus back to the
control when this happens and suppress Access's error warning.

Any help?


ERROR: *****

You cannot add or change a record because a related record is required in
table 'myTable'

CODE: ******

Private Sub cboMyCombo_AfterUpdate()
If Me.Dirty Then
If Not IsNumeric(Me.cboMyCombo) Or IsNothing(Me.cboMyCombo) Then
MsgBox "You must select a record", vbCritical,
CurrentDb().Properties("AppTitle")
Me.cboMyCombo.SetFocus
Exit Sub
End If
End If

End Sub
 
Use the ComboBox's BeforeUpdate event to test that there is a value in the
combo box; also use the form's BeforeUpdate event to do the same.
 
The Form's BeforeUpdate event catches it, but Access's error message follows
my message box.

How can i catch or suppress Access's error message?
 
I should mention that my situation is being caused by referential integrity
violation, the BeforeUpdate event method I'm using would normally
bullet-proof error control on the control.
 
Set the Cancel variable to True in the code just before you show your
message box:
Cancel = True
MsgBox "message"
 
Back
Top