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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AutoExec to run VBA code

Status
Not open for further replies.

HolyGrail

MIS
Sep 8, 2005
10
US
I have been unsuccessful in utilizing the AutoExec macro to open a form and run VBA code associated with three Command Tool Buttons on that form.

any help/direction is greatly appreciated.

Thanks
 
A Macro can do things like open forms and run public functions form a Module. An event sub in a form is private to that form so you will not be able to call it directly.

What you will have to do is:
Create a public Sub in your Form module e.g.
Code:
Public Sub PushButton1()
  Command1_Click
End Sub

Create a public function in a module to call the form's public Sub e.g.
Code:
Public Function CallPushButton1()
  Forms("Form1").PushButton1
End Function

Finally, in the Macro you can use the RunCode method and set the function to CallPushButton1

But, since most of your work is not in code, you could just have the AutoExec call one function and let that function do it all.
 
Thank you for the replay; however, I am still having some difficulty. I do understand the concept of having the Public Module call the public function on the form to run the code associated with the Command Tool Button.

I am receiving an Action Failed message.

This is what I have ...

1)"frmLiquid" with a Command Tool Button named Command24
2)Module TEST with the code that you had suggested for the Module
3) The Public Sub in frmLiquid with Command24_Click (instead of Command1_Click).

Please advise ~ Thank you very much
 
How are ya HolyGrail . . . . .

Post the code for the three buttons and the form name?

Calvin.gif
See Ya! . . . . . .
 
More likely you did not call the function from the macro correctly. In my example, the Macro would need CallPushButton1() in the function name text box of the RunCode macro command.

 
I have condensed the issue ...

The form is frmLiquid

The Button is Command1

The code is a simple docmd.hourglass false attached to the button Command1

The Macro is AutoExec with an Action of RunCode and a Function name of CallPushButton1()

The Module name is TEST with the following code ...

Public Function CallPushButton1()
Forms(frmLiquid).Command1
End Function
 
And is frmLiquid open ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I do have the form open in the AutoExec Macro. Open form, then RunCode.
 
HolyGrail . . . . .

Your fighting it and making it harder on yourself. In you latest post the simplist thing to do is [blue]include the HourGlass method in your Public Function.[/blue] If you look at it, this method can be executed from anywhere! . . . [blue]its not form related![/blue] . . . and as already related to by [blue]PHV[/b][/blue], the form has to be open to access public routines/functions.

Now . . . any code you have that needs to be accessed by more than one source, [blue]you need to make a public routine that can be called by all.[/blue] For you . . . [blue]this is a call from Click events and a call from AutoExec.[/blue] The only real problem here is wether you reside the code in a form module or the modules window. Using the modules window [blue]just changes how you reference forms and things. So considering your origional 3 buttons, you should have:
[ol][li]Three public routines in a module in the modules window that can be called from anywhere (including respective Click events).[/li]
[li]A function called by AutoExec Macro that executes the three routines as required.[/li][/ol]

Calvin.gif
See Ya! . . . . . .
 
How do I turn off the automatic "virus scan/e-mail approval" when I am automatically sending a report via e-mail from MS Access?

ie. the message that I am receiving is ....

"A program is trying to automatically send e-mail on your behalf.
Do you want to allow this?
If this is unexpected, it may be a virus and you should choose "No".


Thanks
 
Do a google search for outlook object model guard

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Does anyone have code to bypass the MS Outlook Object Model Guard when trying to send an e-mail from a MS Access Application?
 
How can I delete a XLS file, within the same directory/folder, from within another XLS file's VBA code?Thanks ~
 
Ask the VBA help for Kill.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
When creating a query with the Query Wizard in MS Access 2000, and then selecting the SQL button to view the code ... I am noticing that MS Access is adding the phrase "With Owner Access Option" at the end of every query.


What is this?
 
How can I automatically attach (via code) a list of parameters (see below) from a MS Access table export to a text file?

!SCENARIO=Actual
!VIEW=Periodic
!YEAR=2006
!PERIOD=Apr
!ENTITY=Northwest_Assn
!VALUE=USD
!ICP=[ICP None]
!COLUMN_ORDER=Account,Custom1,Custom2,Custom3,Custom4
!DATA


This is to prepare the text file to be loaded into a Hyperion Application.


thanks ~ S
 
Please, keep in mind this simple rule:
ONE thread, ONE topic.
And read carefully the second FAQ in my sig.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top