Solved

Ensure the codes would be fired at startup

Posted on 2015-01-28
8
31 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 26

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 26

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 26

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 26

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

747 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

10 Experts available now in Live!

Get 1:1 Help Now