Custom Error Message

  • Thread starter Musa via AccessMonster.com
  • Start date
M

Musa via AccessMonster.com

I'm trying to display a custom error message if the person misses entry in
ANY of the Fields. Is there another way I can have the Error message display
BEFORE the record saves and moves onto the next form ? It seems the code
works up until a point. It displays what items require entry but when I click
OK (on the error message to go back and fill-in the required fields) the form
closes and moves onto the next form.
 
M

Marshall Barton

Musa said:
I'm trying to display a custom error message if the person misses entry in
ANY of the Fields. Is there another way I can have the Error message display
BEFORE the record saves and moves onto the next form ? It seems the code
works up until a point. It displays what items require entry but when I click
OK (on the error message to go back and fill-in the required fields) the form
closes and moves onto the next form.


Use the form's BeforeUpdate event to check all the controls.
If any of them are Null, use:
Cancel = True
to prevent the record from being saved.

The code could be something like:

Dim fld As DAO.Field
Dim bolEntered As Boolean
For Each fld In Me.Recordset.Fields
bolEntered = bolEntered Or IsNull(fld.Value)
Next fld

If bolEntered Then
MsgBox "you forgot to enter a value for " & fld.Name
Cancel = True
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top