Link to home
Start Free TrialLog in
Avatar of piva1970
piva1970

asked on

Crystal Reports - executing and passing parameters to .bat file

Is there any way to execute .bat file from Crystal Reports and then pass parameters to .bat file?
Avatar of Mike McCracken
Mike McCracken

I don't believe so.

What are you trying to do?

mlmcc
You can use a UFL. Check this one, it is free:
http://www.viksoe.dk/code/u2lwin32.htm

It supports ShellExecute , which can be used in your scenario
Avatar of piva1970

ASKER

I try to rename Excel file. So, my idea is to pass Crystal parameter value to .bat file and then .bat file will rename Excel file.
I assume you are exporting the report to the Excel file.  The problem with that idea is the file isn't created permanently until the export is complete.  The UFL would run before that so the file wouldn't exist when the UFL runs.

How are you exporting?

You could easily do this in an application that does the export and when the export is complete then from the application rename the file.

I believe you can also pass the file name to the export and the export will be to the file you want.

mlmcc
Yeah , you cannot use UFL because the file will still not exist. You might check this thread to see how you can force the bat file to wait some time before to proceed :https://www.experts-exchange.com/questions/22794038/Wait-or-delay-a-Bat-file.html

This probably will work if you run the bat file from the last page footer and set the wait to 10-15 seconds , however the whole concept doesn't sound right.

There are bunch of crystal reports viewers and schedulers which can be used to create the excel file directly and they will take care about the proper naming. If you need to export some data to a table without formatting you don't need even crystal reports some viewers are able to retrieve the data and export it directy without using a crystal report. If you tell us more about the process - who is running the report , what kind of data is exported ( tabular , formatted / non formatted , do you have charts or images  etc ...)  we might be able to give you ideas how to handle this better.
I want Crystal Parameter value to pass to .bat file and then .bat file will rename Excel file according to Parameter value to the Excel file name my Crystal is reporting on. Note that Excel is data source for my Crystal report but because I can't change the name of Excel file on the fly (based on Crystal parameter value) I want to identify Excel file name (based on Crystal parameter value)  from the list of Excel files and rename it to one that my reports is based on using .bat file.
Are you trying to rename the excel file which is used as datasource ? I would not suggest that. Ask them to accept the option with access or sqlserver database.

The whole idea to have excel as a datasource is not good. This is just a file with an open structure . Could be changed , locked etc.. which means the report might fail and you will be not able to explain why. However if you can control the environment you might be able to develop an acceptable solution.
To rename the excel file means that nobody (including you ) will know what is the current database name ( it will be one name from a list) and it cannot be used from 2 processes simultaneosly because the second one will be not able to rename the file until the first one is working with it.
Are you trying to select the Excel file to use for the report?

mlmcc
Mlmcc, that's correct.
Client don't want to load Excel content to SQL Server and then use SQL Server talbes as a data source. Vasto everything is correct you said but they want to go with the cheapest option.
ASKER CERTIFIED SOLUTION
Avatar of vasto
vasto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I posted a sample report to your other question that just uses Excel tables and provides a mechanism for selecting the table.

It is not very elegant but I believe it will work.

Another option is to run the report through an application that allows the user to select the Excel file, copies it to the location and name the report is expecting and then runs the report.

mlmcc
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
The last 3 comments by vasto, mlmcc, and IdoMillet are all viable options and solutions.

mlmcc
There are answers there.  As I stated the last 3 comments are valid answers

mlmcc