Solved

Run Access report after batch file has completed

Posted on 2013-05-21
6
436 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
ID: 39185064
It sounds like a timing issue in the batch file.  Can you post the batch file?
0
 

Author Comment

by:printmedia
ID: 39185072
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
ID: 39185118
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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

Author Comment

by:printmedia
ID: 39185164
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
ID: 39185177
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
ID: 39185181
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

777 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