Skip to Content
author's profile photo Former Member
Former Member

Report is not printing directly when there is a sub report

Dear Experts,

I am having an issue with directly printing the report (without loading the preview) in CR 9. I am using VFP to programmatically call the report to be printed in printer directly without any prompt message or dialog boxes.

When I had to change the report to cater a sub report, I found that my code is not working. Do we have to call printout methos seperately for sub reports too?

Following is my VFP code

PARAMETERS aCreport,aCfile,par1,par2,par3,par4,par5,par6,par7,par8,par9,par10,par11,par12,par13,par14,par15,par16,par17,par18,par19,par20,par21,par22,par23,par24,par25,par26,par27,par28,par29,par30

RELEASE goForm

PUBLIC goForm, lnRecordPrinted

lnRecordPrinted=0

DECLARE INTEGER CreateDC IN WIN32API ;

INTEGER lpszDriver, ;

STRING @ lpszDevice, ;

INTEGER lpszOutput, ;

INTEGER lpInitData

LOCAL nRptlen, nTbllen

nRptlen=ALEN(aCreport,1)

nTbllen=ALEN(aCfile,1)

DECLARE aCreport(nRptlen,1), aCfile(nTbllen,2)

goForm = CREATEOBJECT("form1")

IF TYPE('goForm') = 'O' AND !ISNULL(goForm)

goForm.RELEASE()

ELSE

??CHR(7)

MESSAGEBOX("Can not create form", 16, _SCREEN.CAPTION)

ENDIF

DEFINE CLASS form1 AS FORM

ICON = SYS(5)+"\Global\bmps\ds.ico"

NAME = "Form1"

WINDOWTYPE = 1 && Modal

WINDOWSTATE = 2

LOCKSCREEN=.T.

CAPTION=""

ADD OBJECT olecontrol1 AS OLECONTROL WITH ;

NAME = "oleCRViewer", ;

OLECLASS = 'CRviewer9.CRviewer.9.2'

*----------------------------------------------

PROCEDURE INIT

LOCAL cr AS crViewer.crViewer

oCrystal = CREATEOBJECT("CrystalRuntime.Application.9")

LOCAL cMCrysRepo,cSCrysRepo,cCrysFile,cRpt,cTbl,cModuleNo,nRptlen,nTbllen

PUBLIC cMCrysRepPath,oReport

cModuleNo=IIF(!EMPTY(pModuleNo),ALLTRIM(pModuleNo)+"\","")

nRptlen=ALEN(aCreport,1)

nTbllen=ALEN(aCfile,1)

NOTE : Report Count

IF nRptlen>0

NOTE : Main Report

cRpt=aCreport(1) && First Report Must Be The Main Crystal rpt

IF !EMPTY(cRpt) AND VARTYPE(cRpt)="C"

cMCrysRepo = ga.cCrystalPath+"\"+cModuleNo+ALLTRIM(cRpt)+".rpt"

NOTE : If required build in the rpt into the exe

A=FILETOSTR(cMCrysRepo) && Read the file in the EXE to a memory variable

=STRTOFILE(A,cMCrysRepo) && Copy the variable back to a "real" file on the local drive

NOTE : Coping Main Report tables to fox2x

oReport =oCrystal.OpenReport(cMCrysRepo)

IF oReport.HasSavedData

oReport.DiscardSavedData()

ENDIF

lFirst=.T.

ntblseq=0

FOR i=1 TO nTbllen

IF aCfile(i,1)=cRpt

cTbl=UPPER(aCfile(i,2))

IF !EMPTY(cTbl) AND VARTYPE(cTbl)="C"

ntblseq=ntblseq+1

IF lFirst && Main table name will be same as report

cCrysFile = ga.cCrystalPath+"\"+cModuleNo+ALLTRIM(cRpt)+".dbf"

lFirst=.F.

ELSE

cCrysFile = ga.cCrystalPath+"\"+cModuleNo+ALLTRIM(cTbl)+".dbf"

ENDIF

SELECT &cTbl

GO TOP

COPY TO &cCrysFile TYPE FOX2X

NOTE : Support to change report table path dynamically. Always set the table property in the Crystal "Same as Report".

oReport.DATABASE.TABLES.ITEM(ntblseq).SetTableLocation(cCrysFile,JUSTSTEM(cCrysFile),"")

ENDIF

ENDIF

ENDFOR

IF nRptlen>1

NOTE : Sub Report

FOR i=2 TO nRptlen

cRpt=aCreport(i)

IF !EMPTY(cRpt) AND VARTYPE(cRpt)="C"

cSCrysRepo = ALLTRIM(cRpt)

NOTE : Coping Sub Report tables to fox2x

oSReport =oReport.OpenSubreport(cSCrysRepo)

IF oSReport.HasSavedData

oSReport.DiscardSavedData()

ENDIF

lFirst=.T.

ntblseq=0

FOR j=1 TO nTbllen

IF aCfile(j,1)=cRpt

cTbl=UPPER(aCfile(j,2))

IF !EMPTY(cTbl) AND VARTYPE(cTbl)="C"

ntblseq=ntblseq+1

IF lFirst && Sub Report table name will be same as report

cCrysFile = ga.cCrystalPath+"\"+cModuleNo+ALLTRIM(cRpt)+".dbf"

lFirst=.F.

ELSE

cCrysFile = ga.cCrystalPath+"\"+cModuleNo+ALLTRIM(cTbl)+".dbf"

ENDIF

SELECT &cTbl

GO TOP

COPY TO &cCrysFile TYPE FOX2X

NOTE : Support to change report table path dynamically. Always set the table property in the Crystal "Same as Report".

oSReport.DATABASE.TABLES.ITEM(ntblseq).SetTableLocation(cCrysFile,JUSTSTEM(cCrysFile),"")

ENDIF

ENDIF

ENDFOR

ENDIF

ENDFOR

ENDIF

ELSE

NOTE : Main Report not defined properly

cMCrysRepo=""

ENDIF

ELSE

NOTE : Main Report not defined properly

cMCrysRepo=""

ENDIF

NOTE : Used to check whether rpt exist before displaying report

cMCrysRepPath=cMCrysRepo

oReport.EnableParameterPrompting=.F.

ocParm = oReport.ParameterFields()

oParm1 = ocParm.ITEM(1)

oParm1.SetCurrentValue(par1)

oParm2 = ocParm.ITEM(2)

oParm2.SetCurrentValue(par2)

oParm3 = ocParm.ITEM(3)

oParm3.SetCurrentValue(par3)

oParm4 = ocParm.ITEM(4)

oParm4.SetCurrentValue(par4)

oParm5 = ocParm.ITEM(5)

oParm5.SetCurrentValue(par5)

oParm6 = ocParm.ITEM(6)

oParm6.SetCurrentValue(par6)

oParm7 = ocParm.ITEM(7)

oParm7.SetCurrentValue(par7)

oParm8 = ocParm.ITEM(8)

oParm8.SetCurrentValue(par8)

oParm9 = ocParm.ITEM(9)

oParm9.SetCurrentValue(par9)

oParm10 = ocParm.ITEM(10)

oParm10.SetCurrentValue(par10)

oParm11 = ocParm.ITEM(11)

oParm11.SetCurrentValue(par11)

oParm12 = ocParm.ITEM(12)

oParm12.SetCurrentValue(par12)

oParm13 = ocParm.ITEM(13)

oParm13.SetCurrentValue(par13)

oParm14 = ocParm.ITEM(14)

oParm14.SetCurrentValue(par14)

oParm15 = ocParm.ITEM(15)

oParm15.SetCurrentValue(par15)

oParm16 = ocParm.ITEM(16)

oParm16.SetCurrentValue(par16)

oParm17 = ocParm.ITEM(17)

oParm17.SetCurrentValue(par17)

oParm18 = ocParm.ITEM(18)

oParm18.SetCurrentValue(par18)

oParm19 = ocParm.ITEM(19)

oParm19.SetCurrentValue(par19)

oParm20 = ocParm.ITEM(20)

oParm20.SetCurrentValue(par20)

oParm21 = ocParm.ITEM(21)

oParm21.SetCurrentValue(par21)

oParm22 = ocParm.ITEM(22)

oParm22.SetCurrentValue(par22)

oParm23 = ocParm.ITEM(23)

oParm23.SetCurrentValue(par23)

oParm24 = ocParm.ITEM(24)

oParm24.SetCurrentValue(par24)

oParm25 = ocParm.ITEM(25)

oParm25.SetCurrentValue(par25)

oParm26 = ocParm.ITEM(26)

oParm26.SetCurrentValue(par26)

oParm27 = ocParm.ITEM(27)

oParm27.SetCurrentValue(par27)

oParm28 = ocParm.ITEM(28)

oParm28.SetCurrentValue(par28)

oParm29 = ocParm.ITEM(29)

oParm29.SetCurrentValue(par29)

oParm30 = ocParm.ITEM(30)

oParm30.SetCurrentValue(par30)

* SK 20072016

lcPrinter = SET("Printer",2)

lnHDC = CreateDC(0,lcPrinter,0,0)

oReport.PrinterSetup(lnHDC)

oReport.PrintOut()

* oReport.PrintOut(.F.)

* SK Ends

lnRecordPrinted=oReport.PrintingStatus.NumberOfRecordPrinted

ENDPROC

PROCEDURE ERROR

LPARAMETERS nError, cMethod, nLine

IF nError != 1440

DODEFAULT()

ENDIF

ENDPROC

PROCEDURE UNLOAD

RELEASE cMCrysRepPath,oReport

RETURN lnRecordPrinted

ENDPROC

PROCEDURE ACTIVATE

WAIT CLEAR

IF !FILE(cMCrysRepPath)

WAIT WINDOW "Print Report Not Define Properly.................." NOWAIT

THISFORM.RELEASE

ENDIF

ENDPROC

ENDDEFINE

**************************************************

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on Jul 20, 2016 at 08:04 PM

    See if setting the db location to the subreport helps.

    Other than that, it really is time to update the app. You will have problems running it on current Operating Systems as the ActiveX controls will not work. (CR 9 was released in 2002, so you're about 14 years behind the time.).

    Your options as far as updates go; CR SDK for .NET or CR SDK for Eclipse. Both available for free. The RDC was retired in CR XI R2 (v. 11.5) which went out of support about 4 years ago.

    - Ludek

    Senior Support Engineer Product Support, Global Support Center Canada

    Chat with SAP Support! See KBA 2213344 - Starting a chat with SAP Support [video]

    Follow me on Twitter

    Got Enhancement ideas? Use the SAP Idea Place

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.