Hi Dewaputra ... this what i've done 
Code:
Option Explicit
'/ i'm makin it as Procedure
Sub view_rpt(iNum As Integer) '/ fill the parameter values with ListBox Listindex
'* I HAVEN'T TESTED THIS PROC, so tell me if there's somethin wrong ( i don't have any C.Report install on ma computer )
Dim Report As New CrystalReport1 '/ use as local var in this proc
Dim sBuff As String
Screen.MousePointer = vbHourglass '/ change to busy mouse pointer
'** it should be there's set up for .DataFiles(x), Database etc properties
'// before this line
Select Case iNum '/ put query into variable sBuff
Case 0
'/ try usin <Between> and try to make it as Variable..more save, Mmm...it will look like this
'sBuff = "{Quatity.Date} BETWEEN ..... AND .....
sBuff = "{Quatity.Date} in DateTime (" & FrmRep.TxtTh.Text & "," & FrmRep.CmbBln.Text & "," & FrmRep.CmbTgl.Text & ") to DateTime (" & FrmRep.TxtTh1.Text & "," & FrmRep.CmbBln1.Text & "," & FrmRep.CmbTgl1.Text & ")"
Case 1
sBuff = "select * from quatity order by draw_no" 'sort report ascending with draw_no field
Case 2
sBuff = "select * from quatity order by customer" 'sort report ascending with customer field
Case 3
sBuff = "select * from quatity order by proses" 'sort report ascending with proses field
Case 4
sBuff = "select * from quatity order by job_no" 'sort report ascending with job_no field
Case 5
sBuff = "select * from quatity order by opt_id" 'sort report ascending with opt_id field
End Select
'** the rem code below, use for passing selection formula to Report Obj
'-> this code -> Report.DataDefinition.RecordSelectionFormula = sBuff
Report.DataDefinition.RecordSelectionFormula = sBuff
'** if you want to passing selection formula by Viewer Control
'-> this code -> CRViewer1.SelectionFormula = sBuff
'// after we select the record, then set to viewer source properties
CRViewer1.ReportSource = Report
'// viewing the rpt
CRViewer1.ViewReport
'// change MP to default again
Screen.MousePointer = vbDefault
'// Mmm...try it first, bye
End Sub
Private Sub Form_Load()
'Screen.MousePointer = vbHourglass
'CRViewer1.ReportSource = Report <- it will view with default source, that is ( * ) all
'Screen.MousePointer = vbDefault <- should be write after all process has been done
'Select Case FrmRep.CmbFilter.ListIndex <- for this till END SELECT, try with above..to passing the selection
' Case 0
' Report.RecordSelectionFormula = "{Quatity.Date} in DateTime (" & FrmRep.TxtTh.Text & "," & FrmRep.CmbBln.Text & "," & FrmRep.CmbTgl.Text & ") to DateTime (" & FrmRep.TxtTh1.Text & "," & FrmRep.CmbBln1.Text & "," & FrmRep.CmbTgl1.Text & ")"
'// it will be done (viewing your record) if you add this line below _
CRViewer1.ReportSource '// but, this is for the second time you'll write it
' CRViewer1.ViewReport
' Case 1
' Report.SQLQueryString = "select * from quatity order by draw_no" 'sort report ascending with draw_no field
' CRViewer1.ViewReport
' Case 2
' Report.SQLQueryString = "select * from quatity order by customer" 'sort report ascending with customer field
' CRViewer1.ViewReport
' Case 3
' Report.SQLQueryString = "select * from quatity order by proses" 'sort report ascending with proses field
' CRViewer1.ViewReport
' Case 4
' Report.SQLQueryString = "select * from quatity order by job_no" 'sort report ascending with job_no field
' CRViewer1.ViewReport
' Case 5
' Report.SQLQueryString = "select * from quatity order by opt_id" 'sort report ascending with opt_id field
' CRViewer1.ViewReport
'End Select
'the problem is :
'-> i don't see any line that set the DataFiles(x) or else properties
'-> all u want is to select the records, but you have set the report source first _
Report.RecordSelectionFormula = ".." <- it should be first, then _
CRViewer1.ReportSource = Report <- this line after above has been done
view_rpt FrmRep.CmbFilter.ListIndex
End Sub
Private Sub Form_Resize()
If WindowState <> 1 Then
'/ use .Move more effecient and faster _
rather than setting up the rect prop ( .left, .top, .width, .height )
CRViewer1.Move 0, 0, ScaleWidth, ScaleHeight
End If
End Sub
the different with passing the formula :
-> Passing Selection to Report Object, you select the records first then view the result with Viewer Ctrl
Report.DataDefinition.RecordSelectionFormula = sBuff
-> Passing Selection to Viewer Object, the report has been there in viewer obj. ( at real time )
CRViewer1.SelectionFormula = sBuff
other suggest :
Try copy your selection formula to the seagate crystal report program and use the record selection formula to test the formula. Most of the time the error you encounter it due to the report to have the field your try to refer with
Bookmarks