what seems to be wrong with my code... my crystral report viewer was very slow on it first load...

pls. review my code.. thanks,

alexis23



VB Code:
  1. Private Sub Form_Load()
  2.  
  3.     Dim sSQL As String
  4.    
  5.     CRViewer1.Top = 0
  6.     CRViewer1.Left = 0
  7.     CRViewer1.EnableExportButton = gstrRptExport
  8.     sSQL = gstrRptCmd  ' gstrrptcmd is a global variable that holds a sql statement
  9.     Me.Caption = gstrRptTitle
  10.     If Dir(gstrRptPath) = "" Then
  11.         MsgBox "Report file not found!", vbCritical
  12.         GoTo ReportErr
  13.     End If
  14.     If sSQL = "" Then
  15.         MsgBox "Invalid data retrieval!", vbCritical
  16.         Exit Sub
  17.     End If
  18.    
  19.     On Error GoTo ReportErr
  20.     Set cn = New ADODB.Connection
  21.     cn.CursorLocation = adUseClient
  22.     cn.Open gstrConnectString
  23.    
  24.     Set oRS = New ADODB.Recordset
  25.     oRS.LockType = adLockReadOnly
  26.     oRS.CursorType = adOpenStatic
  27.        
  28.     oRS.Open sSQL, cn, adOpenStatic, adLockReadOnly
  29.     oRS.Requery
  30.    
  31.     Set oApp = New CRAXDRT.Application
  32.     Set oReport = oApp.OpenReport(gstrRptPath, 1)
  33.     oReport.DiscardSavedData
  34.     oReport.Database.SetDataSource oRS, 3, 1
  35.    
  36.     oReport.PaperSize = oReport.PaperSize
  37.     oReport.PaperOrientation = oReport.PaperOrientation
  38.    
  39.    
  40.     Screen.MousePointer = vbHourglass
  41.     CRViewer1.ReportSource = oReport
  42.     CRViewer1.ViewReport
  43.    
  44.    
  45.     Do While oReport.PrintingStatus.Progress = crPrintingInProgress
  46.         'DoEvents
  47.     Loop
  48.     Screen.MousePointer = vbDefault
  49.  
  50.     Exit Sub
  51.  
  52. ReportErr:
  53.    
  54.     MsgBox err.Description
  55.     Exit Sub
  56.  
  57. end sub