alexis23
Feb 27th, 2006, 01:10 AM
i created a common form that will be called by any form
within my project, i just change the value of global variables (gstrRptCmd, gstrRptPaperSize..etc)
actually, i was able to load the report, but it consumes a lot of memory, that's why when i call again the frmcrviewer.frm, the program exits.
im attaching the code i use.. pls. help...
thanks in advance
-- alexis :wave:
' FORM NAME = frmCRviewer.frm
Option Explicit
Dim crxApplication As CRAXDDRT.Application
Dim crxReport As CRAXDDRT.Report
Dim crxDatabase As CRAXDDRT.Database
Dim adoCReportRS As ADODB.Recordset
Dim dbx As ADODB.Connection
Private Sub Form_Load()
Me.Caption = gstrRptTitle
Set dbx = New ADODB.Connection
dbx.CursorLocation = adUseServer
dbx.Open gstrConnectString
Set adoCReportRS = New ADODB.Recordset
Set crxApplication = New CRAXDDRT.Application
Set crxReport = New CRAXDDRT.Report
Set crxDatabase = crxReport.Database
Call InitializeViewer
End Sub
Private Sub Form_Resize()
CRViewer1.Height = Me.ScaleHeight
CRViewer1.Width = Me.ScaleWidth
End Sub
Private Sub InitializeViewer()
On Error Resume Next
' gstrRptCmd is a global variable that containing the sql statement
adoCReportRS.Open gstrRptCmd, dbx, adOpenStatic, adLockReadOnly
Set crxReport = crxApplication.OpenReport(gstrRptPath, 1)
crxReport.DiscardSavedData
crxReport.Database.SetDataSource adoCReportRS , 3, 1
' global variable that holds the paper size and paper orientation
crxReport.PaperSize = gstrRptSize
crxReport.PaperOrientation = gstrRptOrientation
crxReport.Sections("PH").ReportObjects("CompanyName").SetText gstrCompanyName
crxReport.Sections("PH").ReportObjects("ReportTitle").SetText gstrRptTitle
crxReport.Sections("PH").ReportObjects("ReportSubTitle").SetText gstrRptSubTitle
CRViewer1.ReportSource = crxReport
CRViewer1.ViewReport
Do While crxReport.PrintingStatus.Progress = crPrintingInProgress
DoEvents
Loop
Set crxApplication = Nothing
Set crxDatabase = Nothing
Set crxReport = Nothing
End Sub
within my project, i just change the value of global variables (gstrRptCmd, gstrRptPaperSize..etc)
actually, i was able to load the report, but it consumes a lot of memory, that's why when i call again the frmcrviewer.frm, the program exits.
im attaching the code i use.. pls. help...
thanks in advance
-- alexis :wave:
' FORM NAME = frmCRviewer.frm
Option Explicit
Dim crxApplication As CRAXDDRT.Application
Dim crxReport As CRAXDDRT.Report
Dim crxDatabase As CRAXDDRT.Database
Dim adoCReportRS As ADODB.Recordset
Dim dbx As ADODB.Connection
Private Sub Form_Load()
Me.Caption = gstrRptTitle
Set dbx = New ADODB.Connection
dbx.CursorLocation = adUseServer
dbx.Open gstrConnectString
Set adoCReportRS = New ADODB.Recordset
Set crxApplication = New CRAXDDRT.Application
Set crxReport = New CRAXDDRT.Report
Set crxDatabase = crxReport.Database
Call InitializeViewer
End Sub
Private Sub Form_Resize()
CRViewer1.Height = Me.ScaleHeight
CRViewer1.Width = Me.ScaleWidth
End Sub
Private Sub InitializeViewer()
On Error Resume Next
' gstrRptCmd is a global variable that containing the sql statement
adoCReportRS.Open gstrRptCmd, dbx, adOpenStatic, adLockReadOnly
Set crxReport = crxApplication.OpenReport(gstrRptPath, 1)
crxReport.DiscardSavedData
crxReport.Database.SetDataSource adoCReportRS , 3, 1
' global variable that holds the paper size and paper orientation
crxReport.PaperSize = gstrRptSize
crxReport.PaperOrientation = gstrRptOrientation
crxReport.Sections("PH").ReportObjects("CompanyName").SetText gstrCompanyName
crxReport.Sections("PH").ReportObjects("ReportTitle").SetText gstrRptTitle
crxReport.Sections("PH").ReportObjects("ReportSubTitle").SetText gstrRptSubTitle
CRViewer1.ReportSource = crxReport
CRViewer1.ViewReport
Do While crxReport.PrintingStatus.Progress = crPrintingInProgress
DoEvents
Loop
Set crxApplication = Nothing
Set crxDatabase = Nothing
Set crxReport = Nothing
End Sub