Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trap error when index field not completed on a record 1

Status
Not open for further replies.

scriggs

IS-IT--Management
Jun 1, 2004
286
GB
I have a form to add new entries to a table. The table has index fields linked to other tables.

If a user does not fill in all the fields, or clicks into the next row, etc. then Access gives an error message:

"The Microsoft Jet database engine cannot find a record in the table 'tblStockStatus' with key matching field(s) 'intStockStatusID'"

I know why the message is appearing which is fine, what I want to do is trap the error message and give my own message/solution.

I have tried the onCurrent and onDirty events of the form but always get the Access error box. How do I trap the error?
 
You can use Form_Error:

Code:
Private Sub Form_Error (DataErr As Integer, Response As Integer)
      Const REQUIREDFIELD_VIOLATION = 3314
      If DataErr = REQUIREDFIELD_VIOLATION Then
         MsgBox "Tut, tut."
         Response = acDataErrContinue
      End If
End Sub
 
A common way is to enforce all the validation rules in the form's BeforeUpdate event procedure, playing with the Cancel parameter and the SetFocus method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for the replies.

Remou - your solution does not work, I had already tried the form error event but it occurs after the Access error.

PHV - the BeforeUpdate is the correct place, and then I have used setfocus back to the missing field as well as docmd.cancelevent to stop the error appearing. Have a star!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top