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

Run Public Sub HOW?? 1

Status
Not open for further replies.

Cpreston

MIS
Mar 4, 2015
969
0
16
GB
Hi

I am trying to create a public sum that will run the following code when I open a database.

DoCmd.ShowToolbar "Ribbon", acToolbarNo
DoCmd.ShowToolbar "Status Bar", acToolbarNo
DoCmd.NavigateTo "acNavigationCategoryObjectType"
DoCmd.RunCommand acCmdWindowHide

How do I make the module so it runs when my database opens please. I have tried to follow some google links but cannot seem to get it working.
Using Access 2010. Could someone explain how I achieve this please.

Thanks
 
This is how you create a public subroutine.
Code:
public Sub MySub(MyParameters)

End Sub

To make it globally accessible you need to put it in a Module.

Then I assume you have a main form that opens when the app starts? A lot of the time it's the 'Switchboard'.

Simply put a call to your sub in the form open event handler.

I actually have a dedicated login form as my app start form which runs version checking code, login authentication and other stuff.

You'll find this setting under 'File' -> 'Options' -> 'Current Database'


"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
Hi Strongm, I don't know how to do an AutoExec macro for this scenario, I tried copying an example from a link I found but failed.

I added the suggestion from 1DMF and oput into on load for the form and it works ok.

Public Sub Form_Load()
DoCmd.ShowToolbar "Ribbon", acToolbarNo
DoCmd.ShowToolbar "Status Bar", acToolbarNo
DoCmd.NavigateTo "acNavigationCategoryObjectType"
DoCmd.RunCommand acCmdWindowHide
End Sub


Thanks for the replies


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top