Full Version: Macro Error Handling - Missed Required Fields
UtterAccess Discussion Forums > Microsoft® Access > Access Macros
bmay1984
Hi,

I have a "Submit" button on a form that contains required fields. The "Submit" button currently closes the form and requery's the form that the closed form was launched from. As it is currently, if I do not complete all required fields and click submit, it pops the error message about missing a required field, then a message prompting to close the form or not, then a macro failed message. Obviously not a good user experience, so just wondering if I can use macros to alter this behavior or if VBA would be required. I prefer macro, but either way, need some guidance.

Ideally, I would like the form to just pop once message stating that a required field was missed, with two buttons - one returns the user to the form to correct, the other closes the form without saving changes, and neither option would pop any further errors or failed macro windows.

Thanks,
Bill
theDBguy
Hi Bill,

What version of Access are you using? Knowing the Access version may help us determine a more appropriate response to your question.

You should be able to modify the code you have running behind your Submit button to check for required fields first before proceeding with the steps to close the form. For that button, are you using a macro or VBA?

Is this form bound or unbound?
bmay1984
Sorry - added to my signature so I don't forget in the future - Access 2007

Currently it's a macro, bound form. The on-click event is Close (Save=yes).
theDBguy
QUOTE (bmay1984 @ Dec 8 2011, 08:52 AM) *
Sorry - added to my signature so I don't forget in the future - Access 2007

Thank you.


QUOTE
Currently it's a macro, bound form. The on-click event is Close (Save=yes).

Then you should be able to add a Condition column to your macro to check if the required fields are empty or not and proceed with the form close appropriately. For example, you might try something like:

Condition: Len(Forms!FormName.ControlName & "") = 0
Action: RunCommand, Undo

(untested)
Just my 2 cents... 2cents.gif
bmay1984
Perfect - here's what I landed with (attached).

Thanks!
theDBguy
Hi Bill,

Congratulations!

Good luck with your project.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.