Prevent form close

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

Guest

Hello,

I need to create my own error messages for data validation because the
messages need to be in two different languages. When trying to close a form
and there is bad data contained in the focused field, error message 2169 pops
up. Using the form_error event, I have managed to (thanks to this forum) run
my own error message and avoid the english message. My error messages have
been created in a form (rather than a message box) so as I can dynamically
control the content and the font (depending on the language chosen at the
outset) . HOWEVER, when I run my message, the form closes. But if the user
clicks "NO" (they don't want to close and lose their changes, they want to
have another go at re-entering the data), how do I prevent the form from
closing and revert back to the last (bad data) field? (AS it does when error
2169 runs as normal, without being over-written)

Hope this is clear.

Thanks,
Ronnie.
 
HOWEVER, when I run my message, the form closes.

well, first of all, *which* form closes - the data entry form? or the error
message form? we need to know that, and also how about copying the code
you're having the problem with (the entire procedure, and any other
procedures that are called from within the procedure), and pasting it into a
post so somebody can troubleshoot.

hth
 
Hello,

I need to create my own error messages for data validation because the
messages need to be in two different languages. When trying to close a form
and there is bad data contained in the focused field, error message 2169 pops
up. Using the form_error event, I have managed to (thanks to this forum) run
my own error message and avoid the english message. My error messages have
been created in a form (rather than a message box) so as I can dynamically
control the content and the font (depending on the language chosen at the
outset) . HOWEVER, when I run my message, the form closes. But if the user
clicks "NO" (they don't want to close and lose their changes, they want to
have another go at re-entering the data), how do I prevent the form from
closing and revert back to the last (bad data) field? (AS it does when error
2169 runs as normal, without being over-written)

Hope this is clear.

Thanks,
Ronnie.

Code the Form's Unload event:

If MsgBox("Close and lose your data", vbYesNo + vbQuestion,"YourTitle
Here")
= vbYes Then
Else
Cancel = True
Screen.PreviousControl.SetFocus
End If

If you wish to default the Yes/No selection to No then use
vbYesNo + vbQuestion + vbDefaultButton2
otherwise Yes is the default.
 
Fantastic. Thank you. It's working a treat.

fredg said:
Code the Form's Unload event:

If MsgBox("Close and lose your data", vbYesNo + vbQuestion,"YourTitle
Here")
= vbYes Then
Else
Cancel = True
Screen.PreviousControl.SetFocus
End If

If you wish to default the Yes/No selection to No then use
vbYesNo + vbQuestion + vbDefaultButton2
otherwise Yes is the default.
 
Hello again,

Little glitch in using the Unload form event. I have data validation on most
fields using the before update event. When I click on "Yes" to have another
go at entering the data (using the form-error event), all the previous
entries for all the fields go blank. I'm guessing this is the nature of the
unload event. But i really want it to work just like error 2169 where you can
go back to the point where you mucked up, not having to start all over again
or re-enter all the data.

Any clues?

Thanks again!
Ronnie.
 
Back
Top