Solved

Batch or Command File That Runs Custom Sub in Access 2007 Database

Posted on 2013-11-01
5
491 Views
Last Modified: 2013-11-04
I thought I would find my answer in old posts on this topic but couldn't quit find what I was looking for so appoligize in advance if I missed something.

I am looking for a batch file that will execute an Access database custom procedure stored in a standard module. All the code does is run a few Make Table Queries. I would like to provide the file to a few users so that it minimizes their direct interaction with the database itself.

Any assistance with this would be much appreciated. Thank you.
0
Comment
Question by:spaced45
  • 2
  • 2
5 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39617631
Add a Macro to your database, using the RunCommand action to run your function (I believe it needs to be a function, not a Sub).

You can then create a shortcut to open the database, running your macro with this as the target:

"c:\program files\microsoft office\office12\msaccess.exe" "c:\MyFolder\MyDatabase.accdb" /x MyMacro

Open in new window



Change "office12" to reflect the path to the version of Access you have installed, the database path to your own database, and the macro name to your own macro.
0
 
LVL 57
ID: 39617708
The other way to do this is with the /CMD switch on the command line, which let's you pass multiple parameters in and react to them.

 WIthin Access, you use the Command() statement to get what was passed in.

 Based on that, you can then call procedures, run reports, put up forms, or whatever.

Jim.
0
 
LVL 1

Author Comment

by:spaced45
ID: 39622640
Is there a way to not have the database open when you click on the shortcut.
0
 
LVL 57
ID: 39622742
No.  Access will open and execute the macro.  There's no avoiding that with Access iteself.  You can hide the main window as soon as it opens, but you will see a flash.  Error handling needs to be very robust however as any type of unhandled error will result in your app sitting there with you being able to do anything about it.

Outside of Access itself, you could write a "launcher" program that would remain hidden, open Access via OLE automation and also keep it hidden.

Jim.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39623085
In addition to what Jim said (and similar), another possible way to achieve this is to use other development platforms - vb.Net, C#, VBScript are some possibilities.

You'd open a connection to your Access tables with a connection string rather than using automation or directly opening Access with a shortcut.

The downside is that with this you only have access to the tables - you'd have to write and execute the queries in VB.Net (or whatever language).  It is also code intensive - similar in that respect to Access automation, and would be a bit of a learning curve if you are not familiar with that type of coding.

The upside is that you'd have a neatly packaged executable that you could distribute to your users, or a web-based interface. And a plus from a developer's standpoint is that the code for connecting to access, executing the queries, and the queries themselves would all be in one place/one environment.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
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…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

713 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