cancel
Showing results for 
Search instead for 
Did you mean: 

Getting Report.SelectPrinter method to work.

Former Member
0 Kudos

I am using VB 6.0 and CR 8.5 (via the CRAXDRT library -upgrading is not an option at this time).

This code

Report.SelectPrinter "winspool", strPrinter, "Ne00:"

does not work if the program is executed via Windows Scheduled Tasks. It works fine when users run the program interactively. No error is generated, the report just won't print. The strPrinter variable contains a valid network printer name, eg "
srvprxxxx\pr3456789"

Any hints/things to try to getting SelectPrinter to work when the app is running as a Scheduled Tasks would really help.

Here is what I have already tried.

Use the CRPEAuto library instead. Guess what, everything works fine. I would switch to the CRPEAuto library but unfortunately it does not support report parameters with multiple values. There is no CRPEAuto.ParameterFieldDefinition.AddCurrentValue method like there is in CRAXDRT.

If you know of a way to pass a report parameter multiple values using the CRPEAuto library I would be grateful.

I also used the API functions in the crpe32.dll directly. Again, my small test application worked fine but unfortunately this API is not an option because I would lose existing functionality of our in-house dlls already in production.

Is it possible to get the "PrintJob #" (required by the CRPE32 API functions) from the CRAXDRT Report object?

I seem to be in a catch-22 situation. No matter which library/method I try to utilize it fails at some point.

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

All of the technologies you mention are quite old and retired, even the RDC... Nevertheless, I would like a bit of a confirmation. When you say:

"...does not work if the program is executed via Windows Scheduled Tasks. It works fine when users run

the program interactively."

Do you mean that the app created in VB 6 works as a "desktop exe" (user clicks a print button and the app prints), but once you schedule the app nothing happens?

If that is the case, make sure that the printer is visible to the Windows Scheduler. You may want to try a simple VB app that does not use CR, but prints a simple string(?).

As test, try to not select a printer. Let the report print to a default printer. Does this work?

Finally, ensure that you have the latest updates for CR 8.5. You can download that from here:

https://smpdl.sap-ag.de/~sapidp/012002523100005986522008E/cr85devwin_en.zip

Ludek

Former Member
0 Kudos

Getting closer.

1) Added a default printer to the account that executes the scheduled tasks.

2) Commented out the SelectPrinter code.

3) Executed the task. Success!!!

4) Uncomment the Select Printer code.

5) Executed the task again but it printed to the default printer. At least we are getting output now.

I printed the DriverName, PortName and PrinterName to a text file before and after the call to SelectPrinter. Here are the results. B4 line shows the default printer.

B4 Select Printer winspool Ne00:
xxxxxxx\yyyy

Aft Select Printer

Edited by: bruce vde on Sep 18, 2008 9:32 PM

Answers (1)

Answers (1)

Former Member
0 Kudos

Do you mean that the app created in VB 6 works as a "desktop exe" (user clicks a print button and the app prints), but once you schedule the app nothing happens?

Yes. Basically, at night, Task Scheduler executes the same app that users run during the day. It simply uses command line arguments to tell the app to "run process A or B or C etc.". A process Opens the proper report, Sets a parameter or two, Selects a network printer and Prints. Set, Select, Print are called multiple times on the same report. An example, run this report for department A and print on X printer. Run it again for department B and print to Z printer.

Just a note, if I am logged in to Windows and start the Scheduled Task (its "Run As" account is not my account) everything works fine.

Thanks for your suggestions. I will try them and let you know the results.

former_member183750
Active Contributor
0 Kudos

This:

Just a note, if I am logged in to Windows and start the Scheduled Task (its "Run As" account is not my account) everything works fine.

may be a good clue. It may be that the account under which the app works has the correct permissions, but the account that does not work does not see the printers. The Process Monitor utility available from MS may be able to determine if that is the case. Look for any "access denied" messages, be it to folders, files or registry entries. ProcMon can be downloaded from here:

http://www.microsoft.com/technet/sysinternals/Utilities/SysinternalsSuite.mspx

Ludek

Former Member
0 Kudos

may be a good clue. It may be that the account under which the app works has the correct permissions, but the account that does not work does not see the printers. The Process Monitor utility available from MS may be able to determine if that is the case. Look for any "access denied" messages, be it to folders, files or registry entries. ProcMon can be downloaded from here:

The "Run As" account used by the Scheduled Task has Local Admin privs. I will look into ProcMon...