Ensure the codes would be fired at startup

I have these codes

Option Compare Database

Public Function InitApplication()
Dim strTokens() As String
Dim strToken() As String

strCommand = Command()
strTokens = Split(strCommand, "&")
For i = 0 To UBound(strTokens)
  strToken = Split(strTokens(i), "=")
  If strToken(0) = "Report" Then strReport = strToken(1)
  If strToken(0) = "UserName" Then strUserName = strToken(1)
  If strToken(0) = "Password" Then strPassword = strToken(1)
Next i

If strUserName <> "" And strPassword <> "" Then
  'bypass login dialog; just validate login
  If Not IsValidLogin(strUserName, strPassword) Then DoCmd.Quit

  DoCmd.OpenForm "Logon"

If strReport <> "" Then DoCmd.OpenReport strReport

Open in new window

within one module of .adp project, written by Access 2007. How to ensure such codes would be fired upon the startup of the project?
LVL 11
HuaMin ChenSystem AnalystAsked:
Who is Participating?
MacroShadowConnect With a Mentor Commented:
Create a new macro, name it AutoExec, set it to run InitApplication.
It is a little complicated since the connection to SQL is established before any code runs. See this accepted solution for several workarounds. http://www.experts-exchange.com/Database/MS_Access/Q_25342305.html#a27667828
HuaMin ChenSystem AnalystAuthor Commented:
Can you show with more details, to what I should apply to the codes? Thanks.
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

You can create an AutoExec macro which calls the InitApplication function. Note, a connection will be established before the macro runs.
HuaMin ChenSystem AnalystAuthor Commented:
Thanks. Can I have more details/demonstration to your suggested way?
HuaMin ChenSystem AnalystAuthor Commented:
Must we run it through one Excel file, right? Can I have more details to refer to the module of one .adp access project?
I'm not sure how Excel is in the picture, an adp is an access interface used to access sql db's.
HuaMin ChenSystem AnalystAuthor Commented:
If there is a way to directly point to one report within one .adp project, I think better to have one example/demonstration for doing this. Thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.