How to make an AutoEXec macro ?

A

Alison Arulia

Hi

I have been sitting here trying work this out for ages. Please help if you
can

I have an OnClick event on a form (to print a report)

Private Sub PrintReport_Click()
DoCmd.OpenReport "Day Run Report", acViewNormal, "", "", acNormal
End Sub

I have looked in google but the answers are too complecated.

How do I change this the an AutoExec macro. I have tried the run code
section but I can not work out how to do this. Is it very complex ?

Thank you for your time
 
A

Alison Arulia

Sorry Douglas I gave the wrong information in my question.

Say I have an OnClick event (with error handleing) that does many actions.
How can I get this to run as an AutoExec macro

I have tried copying the code into a module and using the run command
pointing at the form and then the MyButton_Click()

But I have only started with access this year and it's a little over my
head.

I would like to be able to run certain events as soon as the access opens so
I think I need an autoexec but I can not get the error handleing into the
macro.

Do I need to create a module with the code in and then (somehow) get the
macro to run this ???


Example
Private Sub MyButton_Click()
On Error GoTo MyButton_Click_Err
DoCmd.OpenForm "MyForm", acFormDS, "", "", , acNormal
DoCmd.Close acForm, "MyForm"
DoCmd.OpenReport "MyReport", acViewNormal, "", "", acNormal
DoCmd.Close acReport, "MyReport"
DoCmd.SendObject acTable, "MyTable", "MicrosoftExcelBiff5(*.xls)",
"(e-mail address removed)", "", "", "", "", False, ""
End Sub
MyButton_Click_Exit:
Exit Sub

MyButton_Click_Err:
MsgBox Error$
Resume MyButton_Click_Exit
End Sub
 
D

Douglas J. Steele

Linq Adams via AccessMonster.com said:
That's one reason why few developers use Macros; Macros don't allow for
error
handling.

Actually, I believe that macros have error handling in Access 2007.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top