Solved

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

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now