March 9th, 2011, 04:20 PM
Access 2003 Macro Condition
I've got a small database that is used to track different issues and activities that are being worked on by people. Nothing major. The main form (Issues) is tied to a couple of tables (Issues, Contacts), and the table values are auto-updated when you type information into the various fields on the form.
The form also has a couple of buttons on it (Create New, Delete, etc.). If you start to create a new activity and enter some but not all of the information in the fields but then click a button, and error is thrown by the associated macro. The problem I'm having is trapping the error and preventing the macro from finishing.
As an example, I have the macro BrowseIssues:On Click. The macro has a couple of statements (Open Form, Requery). What I'm trying to do is the following:
In theory, this should work if you click the BrowseIssues button and all of the fields on the Issues form aren't filled in. However, even if all of the fields are filled in the OnError condition kicks in and stops the macro from running.
BrowseIssues: On Click OnError RunMacro
I've tried to read up on this, but I'm still a little confused. Am I missing something in the condition statement OnError? The parameters for RunMacro are correct, and the associated macro that it calls runs.
Any help on this? How do I get this to work when an error is thrown that the required fields aren't filled in, but not to have the error trap run when they are?
March 10th, 2011, 08:03 AM
Re: Access 2003 Macro Condition
OnError is a very old Basic statement. I already used it about 30 years ago. It looks like OnClick but it is different. OnClick appeared later and is used in a different way.
OnError should be used with Resume something at some place. Resume is necessary to end the OnError event, and maybe you forgot it. With OnClick, you don't need to end the event.
See http://www.cpearson.com/excel/errorhandling.htm , http://www.your-save-time-and-improv...error-vba.html
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!