Solved

Ensure the codes would be fired at startup

Posted on 2015-01-28
8
32 Views
Last Modified: 2015-09-09
Hi,
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

Else
  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?
0
Comment
Question by:HuaMinChen
  • 4
  • 4
8 Comments
 
LVL 27

Expert Comment

by:MacroShadow
ID: 40576862
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
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40576873
Can you show with more details, to what I should apply to the codes? Thanks.
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 40576915
You can create an AutoExec macro which calls the InitApplication function. Note, a connection will be established before the macro runs.
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40576936
Thanks. Can I have more details/demonstration to your suggested way?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 40577031
Create a new macro, name it AutoExec, set it to run InitApplication.
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40577034
Must we run it through one Excel file, right? Can I have more details to refer to the module of one .adp access project?
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 40577449
I'm not sure how Excel is in the picture, an adp is an access interface used to access sql db's.
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40579216
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.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now