Question: In Access 2003/XP/2000/97, I'm using VBA code to set a value on another form and I keep getting a "Run-time error '424': Object Required" error. I can't seem to figure out why it won't work. The object that I'm referencing is valid and it should work. What am I doing wrong?
Answer: The problem isn't your code, it's that the Visual Basic editor does not recognize your form. In fact, the Visual Basic editor will not recognize your form until you've invoked the Code Builder (for your form or any object on your form) at least once.
Let's take a look at an example. In our database, we've created two forms - one called form1 and another called form2. We've invoked the Code Builder on form2.
When we take a look at the Visual Basic editor, we can see that form2 exists, but we can't see form1.
To fix this problem, we'll open form1 in design view. Next, display the properties for the Form object. Click on the button (with the three dots) on the "On Open" event for the form.
When the Choose Builder window appears, select Code Builder and click on the OK button.
Now when you return to the Visual Basic editor, form1 would appear in the list.
You can actually fix this error by invoking the Code Builder on any event in the form (or any one of the objects on the form). We've just chosen the form's "On Open" event for demonstration purposes.
Now when you run your VBA code, the "Object required" error should no longer appear.
No comments:
Post a Comment