Trying to capture an error created in a subform

  • Thread starter Thread starter Lance
  • Start date Start date
L

Lance

I have a form, and a subform.

The subform is linked based on 3 "fields" in the main form.

the subform itself also has a many-one relationship with a client list.

So, the form controls one entity (an organization). The subform
controls many entities (clients participating with the organization).
Within the subform, I can assign those clients to the organization,
through a combo box that pulls the clients from a table.

Now, the problem occurs when the end user enters some data into the
subform, but does not select a client, and then tries to leave the
subform. Obviously, since the client id must exist in the client table,
and no clientID has been selected, the database is getting grumpy. It
says "The microsoft Jet database engine cannot find a record in the
table..." yada yada. I understand completely why this does, and must
come up, but my goal is to trap this error, give the user a message to
the effect of "If you do not complete this record, it will not be
entered", and then give them a message box to choose yes or no, and
then if they choose to leave, have access automatically clear the
record and let them continue what they were doing.

Any advice on how to trap this error? If I can do that, then I will be
able to get the rest done on my own, I just don't know where/how the
error is firing.

Thanks,

Lance
 
Hi Lance,

I would need more info but try in the sub Form to put this code... I believe
the Err is coming from the Form Err, you can then stop it by using
Response = acDataErrContinue


Private Sub Form_Error(DataErr As Integer, Response As Integer)

msgbox DataErr 'see if you get a msgbox displaying err #

Response = acDataErrContinue ' can use to stop it

End Sub


If not you can try in the Main Form

Private Sub subfrmName_Exit(Cancel As Integer)
'Put err handeling ..
On Error GoTo HandleErrors

' rest of code...

exit sub
HandleErrors:
' can trap here..
msgbox Err.Number & " " & Err.Description
End Sub

Hope this helps,
Jeff
 
Back
Top