We would like the user to be able to select different printers and paper size for each report. This setting could be set up and saved once.

To do that, we can create a form as below

To do this, we first create a table called ReportNames.dbf. To create it use command

create table REPORTNAMES (ID int autoinc,REPORT Char(20),NARRATION Char(100))

In this we will enter all frx/lbl file names and their description. This table can then be included in the exe as it will be readonly.

The second table is printers.dbf.

create table PRINTERS (ID int autoinc,REPORTNAME Char(20),PRINTERNM Char(100),PAGESIZE int,PAGENAME Char(30),PORTRAIT L,OUTPUTTO int)

This is the table that saves the report settings of each report. This is to be placed in a subfolder of the user APPDATA folder. The folder should be in the PATH, if it is not the default folder.

I am enclosing reportsetup form. Running this form will open the report setup screen which will update the printers.dbf table. It uses 3 PRGs winapierrmsg.prg, EnumPrinterForms.PRG and winapisupport.PRG. All of them are sourced from http://www.berezniker.com

Printing of report

I have enclosed myclass.vcx that has myreport class. You use that to print the report.

To print a report give commands

loReport=NEWOBJECT('myreport','myclass.vcx')
loReport.alias= AliasOfTheReportCursor
loReport.report= NameOfTheReport
loReport.RunReport

The runreport method will check the printers.dbf for settings. If a record exists in printers.dbf, the frx file will be copied to the temp folder and updated with the settings. This updated file will be used to run the report.

Note: Since the myReport class calls the report, local variables declared by your code will not be visible to the report.

reportpage

10 Responses to Printer Setup of Reports

  • Anil says:

    Great Tool Thanks for sharing… 🙂

  • Plinio says:

    “Index tag not found for cursor object cursor1”.

    Any index?

  • vivek says:

    Hi Tushar,

    I just have one suggestion re this great tool.
    If possible, add a “username” or “userid” (or computername) field to this set-up, because a single report like invoice, for example, would be used by different persons at the same time from different machines. Therefore, for same report, multiple printers may be in use simultaneously.

    So, perhaps while inserting in the table “REPORTNAMES”, we can programatically add another field for userid or computername and also use this while deciding which printer to use.

    Thanks for sharing this tool.

    Vivek

    • tushar says:

      Actually the printers.dbf , which stores the settings of each printer is saved in the subfolder of the users APPDATA folder. So it is already a different settings file for each user.

  • apaustria says:

    Ever considering this working on a terminal services workstation where printer specifically those on USB ports change port setting as user login and logoff on their TS sessions? Thanks for sharing btw.

    • tushar says:

      I have not tried it on a TS session. It should work though as it is based on printer name and not the port. Maybe one should check the existence of the printer before giving the REPORT FORM command

  • Patrick says:

    Thanks Tushar for sharing such a nice tool. Eliminates a great deal of “printer and setup config.” programming both at the user and network level.

Leave a Reply

Your email address will not be published. Required fields are marked *