Detecting a field which cause an error message

  • Thread starter Thread starter John Smith
  • Start date Start date
J

John Smith

I am learning how to create custom error messages.

I know about the "OnError" event of the form, and knows how to replace the
standard error message.

I wish that Access will produce an error message saying something like "You
must put a value in field X" (custom made msgbox)

How can I identify this 'field X' which caused the error message to be
displayed?

e.g Assuming I have 4 required fields.

How can I tell - programmatically - which field caused the error?

I need to inform the user, which field he left blank - by mistake.

Thanks.
 
I need to inform the user, which field he left blank - by mistake.

You may just need to step through the fields and see which one (or
more!) is blank:

If Me!txtReqFldA & "" = "" Then
MsgBox "Please fill in field A", vbOKOnly
Cancel = True
Me!txtReqFldA.SetFocus
Exit Sub
End If
If Me!txtReqFldB & "" = "" Then
MsgBox "Please fill in field B", vbOKOnly
Cancel = True
Me!txtReqFldB.SetFocus
Exit Sub
End If
....

John W. Vinson[MVP]
 
OK that's good and working.

BUT isn't theres a way forAccess to tell me which field/control caused that
error?
 
Back
Top