WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Access

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Launch Access Macro from Commandline


Question:

I am a new user to WinBatch trying to automate a daily process that includes loading a flat file to Access thru an Access macro. I can't figure out the format to execute the Access step.

This is what it looks like:

runwait ("P:\....\TICKETSXMIT1.mdb", "") 

Answer:

Via OLE / COM see:

http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/OLE~COM~ADO~CDO~ADSI~LDAP/OLE~with~Access+execute~a~macro~in~Access.txt

There is another way to launch Access and run a macro without using OLE. You must, however, call the MSACCESS.EXE itself, using the following syntax.

D:\APPS\Microsoft_Office\Office10\MSACCESS.EXE YourApp.MDB /WRKGRP SECURED.MDW /user UserID /pwd YourPassword /x macImportCustomers
The /WRKGRP, /user, and /pwd arguments are required only if your application is secured. However, the /x argument is required, as it calls the desired macro.

Note that I used the fully qualified file name, D:\APPS\Microsoft_Office\Office10\MSACCESS.EXE, to the Microsoft Access executable on my system. I didn't actually hard code the path; I used the Win32 FindExecutableA function to locate it. Here is the code:

BuffSize = 512
hBuff = BinaryAlloc ( BuffSize )
ShellLibFQFN = StrCat ( DirWindows ( 1 ) , 'shell32.dll' )
ResultCode = DllCall ( ShellLibFQFN , long:'FindExecutableA' , lpstr:CustomerMasterFQFN , lpstr:DefaultDataDir , lpbinary:hBuff )

If ResultCode < 33, the function failed, most likely because Access is not properly installed. Otherwise, the path is given by the following statement.

MSAccessBinary = BinaryPeekStr ( hBuff , 0 , BuffSize )

Article ID:   W16596
File Created: 2014:07:18:09:51:38
Last Updated: 2014:07:18:09:51:38