Solved

Ensure the codes would be fired at startup

Posted on 2015-01-28
8
33 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 10

Author Comment

by:HuaMinChen
ID: 40576936
Thanks. Can I have more details/demonstration to your suggested way?
0
 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

772 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