Solved

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

Posted on 2013-11-01
5
487 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

777 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