Search code examples
vbams-accesscompiler-errors

Microsoft Access VBA on open error


Basically I am populating my form with data from a database. For this I have an onopen event with just this code inside:

Me.Requery

Everything worked perfectly fine until yesterday, were out of the sudden an error occured. The error states:

The expression OnOpen you entered as the event property produced the following error: Instruction invalid outside of a type-block.

Aditional it says in the Discription:

  • The expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure]
  • There may have been an error evaluating the function, event or macro.

When I go to show help it says:

This error occurs when an event has failed to run because the location of the logic for the event cannot be evaluated. For example, if the OnOpen property of a form is set to =[Field], this error occurs because a macro or event name is expected to run when the event occurs.

However, when I click the message away, everything loaded correctly.

I am using: -Microsoft Access 2013


Q&A:

Does your code compile successfully?

Yes, the rest works fine. It also loads everything into the form correctly. But Every time I start it, this info filed pops up.

EDIT: I just noticed that all my on click events throw the same error now.

Could you show the whole code?

I actually have everything else commented out to troubleshoot the error. If I delete the onopen event the info box disappears.


Solution

  • As mentioned in the comments, compilation can fix the problem by finding errors like wrong access modifiers
    When compilation goes fine, one should delete the Form_Load function and let IDE recreate it. This fixed my problem thought apparently no change in code was observed.