By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,490 Members | 896 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,490 IT Pros & Developers. It's quick & easy.

Auto Run a Macro

P: 9
Is there a way to have a macro pull a report to print view based on a time?
Jan 4 '08 #1
Share this Question
Share on Google+
6 Replies


ADezii
Expert 5K+
P: 8,597
Is there a way to have a macro pull a report to print view based on a time?
Assume your Database is Test.mdb residing in the C:\Test\ Directory. Create an AutoExec Macro that Opens the Report in whatever Mode you desire. Open the Database as a Schedule Event, the command line would look something like:
Expand|Select|Wrap|Line Numbers
  1. "C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "C:\Test\Test.mdb"
The AutoExec Macro would execute as soon as the Database is opened, then the Action of the Macro would automatically open the Report.
Jan 4 '08 #2

P: 9
Thank you for the reply, but I don't think I asked my question the right way.

I want a macro to run when the computer time equals "11:30:00 PM", is there a way to set the macro to do that?

The database will be open and being worked on, I need this as a reminder to print a time sensitive report.

Any help would be great, thank you.
Jan 4 '08 #3

jaxjagfan
Expert 100+
P: 254
Is this a database that is used during the day for data entry and may be open when the desired time arrives? If no then scheduler or other scheduling software would have to startup the Access DB that the report resides in as stated. If yes then you would need to a timer event (probably set at 45000 (45 secs)) that would check to see what time it is. You can set the interval with code or set it via the form's TimerInterval Property. I did it with code here.
This would open "MyReport" every day at 4:30 PM in preview mode.

Sub Form_Load()

Me.TimerInterval = 45000 'Every 45 Secs

End Sub

Sub Form_Timer()

If Format(Now(),"hh:mm") = "16:30" Then 'Now() = Current Date/Time
DoCmd.OpenReport "MyReport", acViewPreview, , , acDialog
End IF

End Sub

Is it a multiuser database and you need a productivity type report to popup that may or may not be user specific at the end of the day or at various times throughtout the day?
Jan 4 '08 #4

P: 9
No it won't be used by mulitable users, it will be open during operations on one stand alone computer. I just need the print preview of the report to open at 23:30 to remind the user the report is due.

Where would I put the code? It is a macro? A query?
Jan 4 '08 #5

jaxjagfan
Expert 100+
P: 254
No it won't be used by mulitable users, it will be open during operations on one stand alone computer. I just need the print preview of the report to open at 23:30 to remind the user the report is due.

Where would I put the code? It is a macro? A query?
Most of what is posted here is code within a form or a module. Macros are great but have a lot of limitations. If there is a form that is always displayed while the database is open then the code would go in it. When you use the wizards to create buttons to open forms and open reports, it is actually writing the code for you as you make your choices in the wizard.

Open the form in design view and click on the "code" button on menu bar or go to View and select Code. I wrote 2 pieces of code. Each begins with "Sub..." and ends with End Sub" If code already exists in the form scroll thu it and look for Sub Form_Load and Sub Form_Timer(). If they exist then paste the code just before the End Sub line within its appropiate section with the lines beginning or ending with "Sub".

If those lines don't already exist or no code just go to the bottom of the code and paste mine and save the form. You will been to change the "16:30" to "23:30".

FYI - Always backup your databases before attempting something like this. Especially if it is a business critical app and you are not positive on what you are doing. I would make a copy of the database and try it out a couple of times with the copy first. Boss will give ya and "Atta-boy" if it works but if ya crash the working db the boss may sound more like Yosemite Sam.
Jan 4 '08 #6

P: 9
jaxjagfan - thanks for the help, it works great, you are life saver, they think I know what I am doing now

and for your help I will be a jax fan this playoffs
Jan 7 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.