Solved

Ensure the codes would be fired at startup

Posted on 2015-01-28
8
35 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

749 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