Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-11-01
5
Medium Priority
?
495 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 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 58
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 58
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

722 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