Closing a subform without running a macro to check for required information

bri822

Registered User.
Local time
Today, 19:49
Joined
May 23, 2002
Messages
31
My problem:
I needed to write a macro to check to see if all the required fields are filled in. It gives user friendly errors, not like setting the required property on a table.

I set this macro to run "on exit." It is working well for that purpose. The problem I am having, is that if I want to close the form and not save the informaion, it still runs the macro and won't close till you enter in all the required fields.

This is just one part of the form. There are other parts of the form that are tabs that the user goes to before saving the information. I have tried running the macro when you go to the next page, but it can't find the fields in teh subform to set focus.

While I am at it, I was curious if anyone knew how to write conditional code for a macro, that would check to see if a check_box is checked or not. I have tried it a couple ways, and it does not seem to be working.

Thank you very much for any help, I am really stuck on this problem!

Brian
 
The code really isn't working now. The BeforeUpdate and AfterUpdate events of the form run BEFORE the Exit event. Therefore, regardless of what error messages your code is displaying, the data has already been saved. Think of it as closing the barn door after the horse after the horse got out.

To solve the problem, move the code (and you should convert it to code rather than using a macro) to the BeforeUpdate event. If any errors are found, cancel the update event with the following line of code:
Cancel = True

Then in the Click event of your Close without saving button, back out the update so that the BeforeUpdate event will not run using the following line of code:
Me.Undo
 

Users who are viewing this thread

Back
Top Bottom