Solved

Run Access report after batch file has completed

Posted on 2013-05-21
6
413 Views
Last Modified: 2013-05-21
Hi all.

I have a batch file that runs a SQL Server 2000 DTS. This DTS copies some tables that will be used in an Access report.

How can I go about opening the Access report AFTER the batch file has completed?

I tried using an Access macro, first I ran the batch file and the next step was to open the report but what would happen was the batch file would run and while it was running the access report was opened, this was causing incomplete data to appear on the report because the report was opening while the batch file was copying the tables. How can I fix this?

Thank you in advance.
0
Comment
Question by:printmedia
6 Comments
 
LVL 26

Expert Comment

by:pony10us
Comment Utility
It sounds like a timing issue in the batch file.  Can you post the batch file?
0
 

Author Comment

by:printmedia
Comment Utility
DTSRun /S "ServerName" /N "Copy Tables" /G "{CA005610-A55A-4209-8A3D-A4E99D844D67}" /W "0" /E 

if errorlevel 1 goto error
echo SUCCESSFUL!!!

PAUSE
goto end
:error
echo ERROR!!! 
PAUSE
:end

Open in new window

0
 
LVL 26

Expert Comment

by:pony10us
Comment Utility
Where did you open the access report?  

If you are running Vista or newer then you can use the builtin timeout command. I would place it after the "echo SUCCESSFUL!!!" line and give it a delay of 1 minute to start with and disable keystrokes to break out of it. You can adjust the time by seconds until you get it figured out.

timeout /t 60 /nobreak
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:printmedia
Comment Utility
As a I mentioned above, I tried using an Access macro that would open the batch file and then open the Access report.

The report is in an Access database that is on a shared folder on the server. So your suggestion is to have the batch file open the report?

What syntax? We are on Windows XP machines with Access 2003.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
How are you *actually* running the batch file?

Here is the way I would do this...
Put the Batch file in one sub, and the Open Report code in another:
Sub RunBatch()
    'Your code to run the batch here
End sub

Sub RunReport()
    'Your Open report code here
End sub

Then run them sequentially , like so:

Sub RunAll()
    Call RunBatch
    Call RunReport
End sub

JeffCoachman
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
Comment Utility
Where in this process were you opening the Access Report?

I generally do this by creating a batch file, but since you already have one, you only need to add one line to it, which would look something like (inserted on or after line 5):

"C:\Program Files\Microsoft Office\Office12\msaccess.exe" "C:\Users\firstname.lastname\Documents\Work\Access\Experts Exchange\OpenReport.accdb" /cmd "rpt_Numbers"

This string is broken up into 3 parts:
1.  The path to your access application
2.  The path to the database where the report exists (needs to be in Trusted Location)
3.  the /CMD command followed by the name of the report

In the attached database, I have a simple table (10 records), a form (frm_Splash) and a report (rpt_Numbers).  

frm_Splash is the startup form, and in the Form_Load event of that form, I have code to check and see whether a Command line parameter was passed to the application.  If so, it accepts command line parameter as the name of the report and opens the report in preview mode (it will probably come up behind form).  You can change that action to print the report instead of opening it in design view, or to output the report to a folder using the Docmd.OutPutTo command.

I have disabled the Application.Quit command, but whenever I open the application with a command line parameter, I quit the application when the desired action is complete.

The one other thing you will need to do is make sure that the database where the report resides is in a Trusted Location.  Otherwise, the application will pause when the form is opened to allow you to acknowledge the Security Warning, click the Options button, and then "enable this content".
OpenReport.accdb
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

728 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

10 Experts available now in Live!

Get 1:1 Help Now