Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get a macro in a report to autorun?

Status
Not open for further replies.

estaup

IS-IT--Management
Oct 22, 2002
7
US
I have a macro in a report which runs great, but I have to mannually run it after the document has refreshed.

I put the VBA code into the following format, but it still doen't run.

Code:
Private Sub Document_AfterRefresh

EndSub

The report is set to autorefresh on open. And I have prompts that have to be filled in as well.

Thanks.
 
Make sure the [tt]Sub[/tt] is in the pre-existent [tt]ThisDocument[/tt] module, and not in a user-created module. Document events go there.

If you have done that already, try to debug the code to ensure it's doing what is expected: Place the cursor in the first instruction of the [tt]Sub[/tt], press F9 (switch break point), and refresh the document.

What do you mean by "prompts that have to be filled in"? If they are "user prompts", you should fill them in:
* Document_Open if autorefresh is enabled
* Document_BeforeRefresh if autorefresh is disabled
 
Thanks for responding.

Late yesterday after posting the message and pulling a majority of my hair out, I noticed that my code was in a user module and not part of ThisDocument.

Moved the code and it worked like it should.

Once again thanks for the detailed response.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top