jwcolby
jwcolby at colbyconsulting.com
Mon Jan 2 16:30:07 CST 2012
I am trying to automate opening an access application, harvesting the references to place in a table for later use. Using OpenCurrentApplication it all works well when I open libraries but when I try and open the application then the autoexec or application form tries to open. Which means passing in an argument to tell the app not to do so. But OpenCurrentApplication cannot pass in command line options because it doesn't use the command line to open the application. Application has a SetOption method which allows you to set the CommandLine property, the same property that the application places any actual command line options into as it opens. thus: Function OpenApp(strFEToOpen As String, Optional blnVisible As Boolean = True, Optional strCmdLineArgs As String = "") As Access.Application Dim appAccess As Access.Application Dim strCmdLine As String ' Create new instance of Microsoft Access. Set appAccess = CreateObject("Access.Application") If Len(strCmdLineArgs) Then appAccess.SetOption "Command-line arguments", strCmdLineArgs End If appAccess.Visible = blnVisible appAccess.OpenCurrentDatabase strFEToOpen Set OpenApp = appAccess End Function I then use an method to check that: Function InitApp() ' Check value returned by Command function. If Command <> "" Then Else DoCmd.RunCommand acCmdAppMaximize DoCmd.OpenForm "switchboard" End If End Function And finally I call that method from the Autoexec macro. So when I open the application just by a shortcut, it does not pass in a command line argument, autoexec calls InitApp, and since there is nothing in Command my switchboard opens. When I open it via automation, I call OpenApp passing anything in to the command line arg and the same sequence happens, autoexec calls initApp except now Co,,amd returns the argument I put in it and it does not open my switchboard. I can now automate the application without the normal startup stuff running. -- John W. Colby Colby Consulting Reality is what refuses to go away when you do not believe in it