Solved

Access 2010 Automation

Posted on 2011-09-28
10
243 Views
Last Modified: 2012-05-12
I want to automatically start up Access and run a sub procedure. The Access database runs an update process to a PLSQL database. Right now, I have to open the database, click a button, and wait for the process to complete. I'd rather be able to schedule a script that opens the database, clicks the button, and closes the database when the process is complete.

I attempted to write a batch file that will do this. Here's what I tried:

start msaccess.exe /ro "\\PathToAccessDB\UpdateDB.accdb" /x cmdUpdate_Click

The database starts up, but the problem is that the /x option expects a macro, not a subprocedure.
0
Comment
Question by:Cazar
[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
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 36718617
so create a macro that kicks off the subroutine.

Make sure that your Click event is defined as Public, not Private, as you won't be able to call it from outside your form if it is not public.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 300 total points
ID: 36718648
create a Function "fncUpdate"  in a regular module
 *copy the codes from the click event of the command button cmdUpdate and put them in "fncUpdate"

create a Macro, and save as "macroUpdate"

In the Action column, place

RunCode




Function Name  fncUpdate()



place this in your batch file


start msaccess.exe /ro "\\PathToAccessDB\UpdateDB.accdb" /x macroUpdate






0
 
LVL 10

Expert Comment

by:conagraman
ID: 36719107
just make a macro in your database and name it autoexe
the macro will run when you open the database : )
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 1

Author Comment

by:Cazar
ID: 36719109
Creating a macro and a separate module works, but I was hoping there was a way to just run the existing subprocedure. I have other processes that I need to automate this way. I want to be able to run the processes manually by clicking a button or through scripting. If I have to create a separate module for the scripting, then I will have to keep the module version and the button click version in sync any time I make changes to the code. I'd rather avoid that maintenance overhead if possible.

I think the best solution might be to call the module function used by the macro from the click event of the button instead of giving the button it's own build event code. Both the button and the macro could use the same code then.
0
 
LVL 10

Expert Comment

by:conagraman
ID: 36719154
sorry i ment

name your macro

Autoexec
0
 
LVL 47

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 200 total points
ID: 36719161
"I will have to keep the module version and the button click version in sync "

Not really, just call the function from the click event of your button.
0
 
LVL 10

Expert Comment

by:conagraman
ID: 36719210
call your function from your  "Autoexec" macro
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 36719226
No, don't call the function from the Autoexec, unless you want this function to fire every time you open the application.
0
 
LVL 10

Expert Comment

by:conagraman
ID: 36719233
@ fyed i thought that was what he wanted. my bad
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36719291

<Creating a macro and a separate module works>

make the click event of the command button Public. ie.,

Public Sub cmdUpdate_Click()  '<<

in the function call it like this

Function fncUpdate()

Forms!NameofForm.cmdUpdate_Click

End Function


change "NameofForm" with the actual name of the form where your command button is




0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

735 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