Create warnings

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I create a warning from a form. Say that surname and name are
mandatory fields and the user enters only one or none. Instead of justing
ignoring or displaying an ugly MS warning I would like to say something like
"Hey, numbnuts, you forhot xxx" - until production, where I probably should
say something different :op

Thanks!
 
You could use the form's Before Update event:

If IsNull(Me.txtFirstName) Then
msgbox "First Name is needed"
Me.txtFirstName.SetFocus
End If

If IsNull(Me.txtLastName) Then
msgbox "Last Name is needed"
Me.txtLastName.SetFocus
End If

You could also add the code to a text box event, so that the message can be
triggered is somebody tries to enter address information (or whatever)
without filling in both first and last name fields. In the example,
txtFirstName is the text box bound to the first name field, etc.

By the way, reconsider using facetious or insulting error messages, even at
the development stage. These statements can get buried in the code, then
show up unexpectedly after the database is released. Clients and/or bosses
are unlikely to be amused. I have not risked committing the error myself
since I saw a former co-worker dealing with an irate customer.
 
Lars said:
How can I create a warning from a form. Say that surname and name are
mandatory fields and the user enters only one or none. Instead of justing
ignoring or displaying an ugly MS warning I would like to say something
like
"Hey, numbnuts, you forhot xxx" - until production, where I probably
should
say something different :op

Thanks!

In your form's Before Update event:

If IsNull(Me.txtMyTextBox) Then
MsgBox "Hey, numbnuts, you forhot xxx"
Cancel = True
End If

where txtMyTextBox is your text box's name. I think you'd have to make the
field not "required" to switch off the "ugly" warning, but I'm not sure.

HTH - Keith.
www.keithwilby.com
 
Thanks! :)

Yup, I never really put these in the code - but I do use them in the
scribbling fase.

Cheers :)

Lars
 
Thanks for the help!

That should be enough for me to collect all the fields and then putting
together a proper message for all missing fields instead of using six or
seven boxes.

Cheers :o)
 
Back
Top