hi there,

can you pls review my code, i am calling this form to view my crystal report, my problem is it consume a lot of memory when it loads, that causes the system to crash..

thanks,

VB Code:
  1. Option Explicit
  2. Dim cn As New ADODB.Connection
  3. Dim jro As New jro.JetEngine
  4. Dim oRS As ADODB.Recordset
  5. Dim oApp As CRAXDRT.Application
  6. Dim oReport As CRAXDRT.report
  7.  
  8. Private Sub Form_Load()
  9.    
  10.     Dim sSQL As String
  11.  
  12.     CRViewer1.Top = 0
  13.     CRViewer1.Left = 0
  14.    
  15.     CRViewer1.EnableExportButton = gstrRptExport
  16.  
  17.     sSQL = gstrRptCmd
  18.    
  19.     Me.Caption = gstrRptTitle
  20.    
  21.     If Dir(gstrRptPath) = "" Then
  22.         MsgBox "Report file not found!", vbCritical
  23.         GoTo ReportErr
  24.     End If
  25.     If sSQL = "" Then
  26.         MsgBox "Invalid data retrieval!", vbCritical
  27.         Exit Sub
  28.     End If
  29.  
  30.        
  31.     On Error GoTo ReportErr
  32.     Set cn = New ADODB.Connection
  33.     cn.CursorLocation = adUseClient
  34.     cn.Open gstrConnectString
  35.     Set oRS = New ADODB.Recordset
  36.     oRS.LockType = adLockReadOnly
  37.     oRS.CursorType = adOpenStatic
  38.    
  39.    
  40.     jro.RefreshCache cn
  41.     Set oRS = cn.Execute(sSQL, , adCmdText)
  42.     oRS.Requery
  43.     Set oApp = New CRAXDRT.Application
  44.     Set oReport = oApp.OpenReport(gstrRptPath, 1)
  45.     oReport.Database.SetDataSource oRS, 3, 1
  46.     oReport.PaperSize = oReport.PaperSize
  47.     oReport.PaperOrientation = oReport.PaperOrientation
  48.     On Error Resume Next
  49.     oReport.Sections("PH").ReportObjects("CompanyName").SetText gstrCompanyName
  50.     oReport.Sections("PH").ReportObjects("ReportTitle").SetText gstrRptTitle
  51.     oReport.Sections("PH").ReportObjects("ReportSubTitle").SetText gstrRptSubTitle
  52.     On Error GoTo 0
  53.     Screen.MousePointer = vbHourglass
  54.     CRViewer1.ReportSource = oReport
  55.     CRViewer1.ViewReport
  56.     Do While oReport.PrintingStatus.Progress = crPrintingInProgress
  57.     Loop
  58.     CRViewer1.Refresh
  59.     Screen.MousePointer = vbDefault
  60.     Exit Sub
  61. ReportErr:
  62.     MsgBox Err.Description
  63.     Exit Sub
  64. End Sub