Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass parameter to Access

Status
Not open for further replies.

tommeekers

Programmer
Sep 10, 2003
77
0
0
BE
Is there a way to pass a parameter to Access ?

My application is kind of a wizard-like tool to do a data export and some other stuff. When I just run the application, I have to press the start button to trigger the code. But I also want to be able to schedule this task without having to press the start button. Is this possible by passing a parameter along ? Something like C:\MyApplicationFolder\MyApplication.mdb /autorun ?
So if there is no autorun parameter, the user will see the form and he will be able to press start if he wants to run the code. But when the autorun parameter is used, it has to skip the start button and go directly to the code.

Is this possible or is this a bit of a long shot ?
 
You could also write a little VBScript file. The following opens an instance of Access, then opens a database, then opens a specific form. Then also passes some values to controls on that form. Then creates a report. You can edit this in Notepad. Save it as .vbs To run it, just double click the file name.
Option Explicit
Dim objAccess, objForm
Set objAccess = CreateObject("Access.Application")
objAccess.OpenCurrentDatabase "c:\MDOT.mdb"
objAccess.DoCmd.OpenForm "Sales by Year Dialog"
Set objForm = objAccess.Forms("Sales by Year Dialog")
objForm.Controls("BeginningDate").Value = "1/1/95"
objForm.Controls("EndingDate").Value = "12/31/95"
'build the report
objAccess.DoCmd.OutputTo acOutputReport, "Sales by Year", _
"Snapshot Format", "c:\SalesByYear.snp"
objAccess.Quit

If you're going to leave Access open, do not include the last line objAccess.Quit
 
I used the /cmd method to pass the value autorun to my application. On several places in the code I check this value and if it is set, I just make the application press the buttons automaticly that normally would have to be pressed by the user.

Code:
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "C:\[i]MyApplicationFolder[/i]\[i]MyApplication[/i].mdb" /cmd "autorun"
However, this seems to make my code outrun itself. I call a function resizeappwindow to hide the access toolbars and resize the window right before I call the function checkcommandline to check the command-line parameter. When the parameter is set, a button is pressed and the import code is triggered. But it seems like the import code gets triggered too fast. The function resizeappwindow is still running and gets interrupted by the import code.

How can I make the second function wait till the first one is done ?

 
There are a few ideas in this thread:
Can I pause code execution between statements
thread705-1022052
 
Hmm,

The whole /cmd method does not seem to work on Access Runtime. It returns an unknown application error as soon as I try to get the value of command.

Code:
Function CheckCommandLineStart()
    ' Check value returned by Command function.
    [COLOR=black yellow]If Command = "autorun" Then[/color]
        [COLOR=green]'autorun application[/color]
    Else
        Exit Function
    End If
 End Function
 
What version are you using? I have tried this (Access 2000):
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "C:\Tek-Tips\Tek-Tips.mdb" /runtime /cmd "hello"
And it seemed to work ok.
 
I'm using Microsoft Access 2000.
When I run the application on my machine (which has the full version of Access), it works fine even with the /runtime command.
But when I run the application on a machine which has only Access Runtime installed, it returns that error. I tried re-installing the runtime, but that didn't solve the problem.
I will try the application on another machine now.
 
Why not create a simple macro with two actions, one to run your code and one to quit the db. Then use something like the Handy Access Launcher (HAL) to schedule that macro to be run at set times/intervals. This will enable your code to be run without manual intervention as and when you want.

HAL is available from
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top