473,419 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

Ran a batch file or an MS Access macro shortcut without opening another instance of access

I am trying to use Windows Task Scheduler to run a batch file for an
already open MS Access database. Below is the syntax to the batch file:

Batch file: DailySalesExport.bat
REM This runs the macro that exports the reports to the J drive
PATH = "C:\Program Files\Microsoft Office\Office\;C:\Windows\Command"
START /WAIT Msaccess.exe "D:\acesdata\SALES\Daily2005.mdb" /x
"SnapShotExportDailySales"
EXIT

Its working fine, the only problem is that its opening another instance
of MS Access and i dont want it to do that since that databse is
already open. I have to live it open because the main form has criteria
which the database uses.

I tried saving a shortcut of the macro to my computer:

D:\acesdata\SALES\BatchFiles\SnapShotExportDailySa lesReports.MAM

This works fine when i double click on it from windows explorer but
when i use scheduler to run it opens another instance of ms access too!

Please help

Cliff

Nov 23 '05 #1
4 26766
This may not be worth much, but I have not had much luck with the
Windows scheduler. I write my own schedulers in either VB6 or VB.Net.
You have way more control over Access with a VB app. You can invoke
Access or check if an instance of Access is already running (just check
if the corresponding ldb file is alive). If it exists, then don't
invoke Access. If there is no ldb for that file, then invoke Access.
You can run subs in Access from a VB app.

Sub RunAccess()
Dim AccApp As Access.Application
AccApp = CType(CreateObject("Access.Application.10"),
Access.Application)
AccApp.OpenCurrentDatabase(Application.StartupPath & "\AccessDB1.mdb")
AccApp.Run("subGetData", d1.ToShortDateString)
AccApp.CloseCurrentDatabase()
AccApp.Quit()
End Sub

This is a sample VB.Net sub. You create the Access Object, open an
Access mdb (which happens to be in the same directory as the VB app --
Application.StartupPath), you run a sub in Access (subGetData) and pass
in an argument (a date arg here)

AccApp.Run("subGetData", d1.ToShortDateString)

When the sub is done, you close Access. The sub runs synchronously here
- means you won't go to the next line of code in the VB app until Access
finishes runnning the sub. Then you close Access down and quit the
Object.

You can set a Timer object in the VB app and set that to run based on
your specs, hourly, daily, twice a day, etc. Way more flexibility than
the Windows Scheduler. Way more reliable.
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Nov 24 '05 #2
Look at scheduling a script file instead. You can then use createobject to
get the current instance of Access and run the macro using automation.

--
Terry Kreft

"CliffKing" <cl*****@msn.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I am trying to use Windows Task Scheduler to run a batch file for an
already open MS Access database. Below is the syntax to the batch file:

Batch file: DailySalesExport.bat
REM This runs the macro that exports the reports to the J drive
PATH = "C:\Program Files\Microsoft Office\Office\;C:\Windows\Command"
START /WAIT Msaccess.exe "D:\acesdata\SALES\Daily2005.mdb" /x
"SnapShotExportDailySales"
EXIT

Its working fine, the only problem is that its opening another instance
of MS Access and i dont want it to do that since that databse is
already open. I have to live it open because the main form has criteria
which the database uses.

I tried saving a shortcut of the macro to my computer:

D:\acesdata\SALES\BatchFiles\SnapShotExportDailySa lesReports.MAM

This works fine when i double click on it from windows explorer but
when i use scheduler to run it opens another instance of ms access too!

Please help

Cliff

Nov 24 '05 #3
Dum, dum, dum...

Strike CreateObject ... insert GetObject.

Fingers running faster than head.
--
Terry Kreft

"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:CP********************@karoo.co.uk...
Look at scheduling a script file instead. You can then use createobject
to get the current instance of Access and run the macro using automation.

--
Terry Kreft

"CliffKing" <cl*****@msn.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I am trying to use Windows Task Scheduler to run a batch file for an
already open MS Access database. Below is the syntax to the batch file:

Batch file: DailySalesExport.bat
REM This runs the macro that exports the reports to the J drive
PATH = "C:\Program Files\Microsoft Office\Office\;C:\Windows\Command"
START /WAIT Msaccess.exe "D:\acesdata\SALES\Daily2005.mdb" /x
"SnapShotExportDailySales"
EXIT

Its working fine, the only problem is that its opening another instance
of MS Access and i dont want it to do that since that databse is
already open. I have to live it open because the main form has criteria
which the database uses.

I tried saving a shortcut of the macro to my computer:

D:\acesdata\SALES\BatchFiles\SnapShotExportDailySa lesReports.MAM

This works fine when i double click on it from windows explorer but
when i use scheduler to run it opens another instance of ms access too!

Please help

Cliff


Nov 24 '05 #4
Thanks for your help

Rich P wrote:
This may not be worth much, but I have not had much luck with the
Windows scheduler. I write my own schedulers in either VB6 or VB.Net.
You have way more control over Access with a VB app. You can invoke
Access or check if an instance of Access is already running (just check
if the corresponding ldb file is alive). If it exists, then don't
invoke Access. If there is no ldb for that file, then invoke Access.
You can run subs in Access from a VB app.

Sub RunAccess()
Dim AccApp As Access.Application
AccApp = CType(CreateObject("Access.Application.10"),
Access.Application)
AccApp.OpenCurrentDatabase(Application.StartupPath & "\AccessDB1.mdb")
AccApp.Run("subGetData", d1.ToShortDateString)
AccApp.CloseCurrentDatabase()
AccApp.Quit()
End Sub

This is a sample VB.Net sub. You create the Access Object, open an
Access mdb (which happens to be in the same directory as the VB app --
Application.StartupPath), you run a sub in Access (subGetData) and pass
in an argument (a date arg here)

AccApp.Run("subGetData", d1.ToShortDateString)

When the sub is done, you close Access. The sub runs synchronously here
- means you won't go to the next line of code in the VB app until Access
finishes runnning the sub. Then you close Access down and quit the
Object.

You can set a Timer object in the VB app and set that to run based on
your specs, hourly, daily, twice a day, etc. Way more flexibility than
the Windows Scheduler. Way more reliable.
Rich

*** Sent via Developersdex http://www.developersdex.com ***


Nov 24 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Tim Eliot | last post by:
Just wondering if anyone has hit the following issue and how you might have sorted it out. I am using the command: DoCmd.TransferText acExportMerge, , stDataSource, stFileName, True after...
4
by: Bill | last post by:
I need help closing a CMD window when it is executed from Access. 1) The batch file is called from Access. 2) Access closes, 3) the batch runs a copy of the access database (creating a backup)...
1
by: Charles | last post by:
I'm trying to write a windows application in C# (Using Microsoft Visual C# 2005 Express) that is nothing more than a simple UI with buttons on it. The buttons do various things like running...
9
by: John | last post by:
Tried this on microsoft.public.access.gettingstarted - no response - perhaps more appropriate here. I'm not a database user, simply helping someone get started with a new computer. The old...
4
by: Jamey Shuemaker | last post by:
A2k2 with user-level security and all preventive measures, vis a vis, Security FAQ enabled or enacted. I've got three DBs, which due to size constraints can't, or rather, probably shouldn't be...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
4
by: Wayne | last post by:
How do I get rid of the generic Windows "Open File - Security Warning" that appears when I try to open a database that resides on another PC on my home network? This is not the annoying macro...
0
by: Mark Gold | last post by:
Hi! We have a VB application using Crystal Reports 6 that has worked successfully on hundreds of systems for over 10 years. Now, on one network, the application and access database does not close....
0
by: ARC | last post by:
Hello all, For right-click (shortcut) menus in access 2007, I've been using a round-about method of opening access 97 on an old computer, modifying my own custom shortcut menus, then importing...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.