getting hung up in required field

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

MES via AccessMonster.com

I'm using the following code to require a user to populate a form field:

If Len(Trim(Nz(Me.UserMnemonic, ""))) = 0 Then
MsgBox "This field is required."
Cancel = True
End If

It suits my need; however, there is one small issue. I would like the user
to either fill in the required field, or close the form. I have a cancel
button on the form that closes the form, but once the user gets to a required
field, if they do not fill it in with something, they get hung up on that
field. Is there any way to use my cancel button without having to first fill
in the field?

Thanks in advance.
 
G

Guest

In the Click event of your cancel button:

If Me.Dirty Then
Me.Undo
End If
Docmd.Close
 
D

Douglas J. Steele

You could have your cancel button set a module-level variable, and change
your code to also check for that variable's value.

Assuming you named the variable mbooOkToCancel and set it True in the Cancel
button, try:

If Len(Trim(Nz(Me.UserMnemonic, ""))) = 0 _
And mbooOkToCancel = False Then
MsgBox "This field is required."
Cancel = True
End If
 
J

Jeff L

What I have done is to use a hidden checkbox on my form and then if
it's checked do one thing, if not then do another.

Make your checkbox (CancelClicked) and set the visible property to No
and Default to False.
In your On Click event of the Cancel button, put Me.CancelClicked =
True. Then close your form.
I am assuming your field checking is in the On Unload event of the
form. In the first line of your code, put
If Me.CancelClicked = False then
Do your field checking
End if

Hope that helps!
 

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