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

AutoExec command

Status
Not open for further replies.

jd20005

Technical User
Nov 11, 2003
11
0
0
GB
I am trying to use the AutoExec command as I started learning Visual Basic last week and I wish a Microsoft Access Database to display a pop up messagebox when it loads. So I have written the following code and stuck it in a module:

Public Sub AutoExec()
Dim MyVal As String
MyVal = "Hello Karen"
MsgBox MyVal
End Sub

But nothing happens when I open the Database and I can't figure out why. Can anyone help the noob? Or if someone could just post a simple bit of code that works with the AutoExec command so I can experiment with it that would be great also.

Thanks.
 
jd20005,

Do you have a form which opens when the db opens?

If so, add your code to the Open event of this form and it should solve your problem.



Leigh Moore
Solutions 4 MS Office Ltd
 
Yes I can attach this code to the main menu form so that it pops up when the main menu is loaded but then whenever the user goes back to the main menu the messagebox pops up therever after. So I want to use autoexec. Anyways I just really want to know how autoexec works and why is doesn't seem to be working for me.
 
Create a module with the code below and name it Test.
Create a macro with the name of AutoExec. In the macro design screen, choose RunCode and at the bottom under Action Arguments in the Function Name type in AutoExec(). Save the database file and then open it back up. Your message box will appear. If you don't want the message box to appear when you open your database, hold down the shift key when you open it. Hope this helps.

Rich

Function AutoExec()
On Error GoTo AutoExec_Err

MsgBox "Hello Karen", vbOKOnly, "AutoExec"

AutoExec_Exit:
Exit Function

AutoExec_Err:
MsgBox Error$
Resume AutoExec_Exit

End Function
 
Hey jd20005

The correct way to use the AutoExec in Access is as follows:

To use AutoExec you need a MACRO called AutoExec and not a module called AutoExec or a module with a sub called AutoExec.

Go to the macros tab, click new, and put a few functions together, one at a time. Save the macro as AutoExec and Tada!! that's all folks.

Just remember to clear the startup form in the startup options, if there is one.

I use this procedure to minimize the database window before I start up a form. It works like a charm.

Enjoy!

Anvil19
 
Why not just take Anvil19's thinking a stage further?

You say you only want to display a pop up message. Presumably you have your message on a form laid out as you want to see it. In Anvil19's method you would have then opened this form in your autoexec macro.

Do away with the macro! Create the message form and then in the startup options (right click on the database window and select 'startup') set the 'display form/page' to open your message form. When the database is run the form will automatically open. You could then get other actions to cascade from the closing of this form, I.e. on closing a main menu opens...

You can also hide the database window from here as well (rather than minimising).



I love deadlines. I like the whooshing sound they make as they fly by. (Douglas Adams)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top