i need ur guys help on crystal report. If i want to print only related records from the database to crystal report, what should i do? (that's say i have several sales records, and i only want to print the sales records of particular date only)
Printable View
i need ur guys help on crystal report. If i want to print only related records from the database to crystal report, what should i do? (that's say i have several sales records, and i only want to print the sales records of particular date only)
Well I don't know what database are you using but the next code is if you use and ODBC CONNECTION BUT you can addapt it.
Set db = OpenDatabase("misord", False, False, "odbc;uid=;pwd=;database=misord;")
CrystalReport1.Connect = "DSN = misord;UID=test;PWD=test;DSQ="
Private Sub OK_Click()
fil1 = filtro1.Text
fil2 = filtro2.Text
fil3 = filtro3.Text
c1 = Combo1.Text
c2 = Combo2.Text
c3 = Combo3.Text
c7 = Combo7.Text
c4 = Combo4.Text
c5 = Combo5.Text
c6 = Combo6.Text
c8 = Combo8.Text
Select Case c1
Case "MSO No."
c1 = "{forma.festo}"
Case "User name"
c1 = "{forma.user_name}"
Case "Status"
c1 = "{forma.status}"
Case "Bill of lading"
c1 = "{forma.x}"
End Select
Select Case c2
Case "="
c2 = "="
Case ">"
c2 = ">"
Case "<"
c2 = "<"
End Select
Select Case c3
Case "MSO No."
c3 = "{forma.festo}"
Case "User name"
c3 = "{forma.user_name}"
Case "Status"
c3 = " {forma.status}"
Case "Bill of lading"
c3 = "{forma.x}"
End Select
Select Case c4
Case "="
c4 = "="
End Select
Select Case c5
Case "MSO No."
c5 = "{forma.festo}"
Case "User name"
c5 = "{forma.user_name}"
Case "Status"
c5 = "{forma.status}"
Case "Bill of lading"
c5 = "{forma.x}"
End Select
Select Case c6
Case "="
c6 = "="
End Select
Select Case c7
Case "and"
c7 = "and"
Case "or"
c7 = "or"
End Select
Select Case c8
Case "and"
c8 = "and"
Case "or"
c8 = "or"
End Select
Set rep = CrystalReport1
'rep.SelectionFormula = "{forma.cons_num} = '150' And {forma.user_name} = 'aurora'"
If c7 = "" And c8 = "" Then
rep.SelectionFormula = "" & c1 & " " & c2 & " '" & fil1 & "'"
Else
If c7 <> "" And c8 = "" Then
rep.SelectionFormula = "" & c1 & " " & c2 & " '" & fil1 & "' " & c7 & " " & c3 & " " & c4 & " '" & fil2 & "'"
End If
End If
If c7 <> "" And c8 <> "" Then
rep.SelectionFormula = "" & c1 & " " & c2 & " '" & fil1 & "' " & c7 & " " & c3 & " " & c4 & " '" & fil2 & "' " & c8 & " " & c5 & " " & c6 & " '" & fil3 & "'"
End If
rep.ReportFileName = "g:\apls\mso\mso2K.rpt"
errorhandler:
Select Case Err.Number
Case 20515: 'Resume Next
MsgBox ("There is an error in the selection")
Resume Next
End Select
On Error GoTo errorhandler
rep.Action = 2
End Sub
What does the Crystal Reports do anyway?
If you're using the report designer component within VB here's a way to set a recordset to a report.
Hope this helps.Code:Dim rstCurrent As ADODB.Recordset
Dim strSql As String
'Declare your report as an object variable
Dim Report1 As rptAdjuster
strSql = "SELECT * "
strSql = strSql & "FROM openclose!adjuster "
strSql = strSql & "WHERE name = 'Derick'"
'This loads a form with a Crviewer control
Load frmReport
'Opens the recordset
Set rstCurrent = New ADODB.Recordset
rstCurrent.Open strSql, fCnn1, adOpenForwardOnly, , adCmdText
'Initializing the report you want to load
Set Report1 = New rptAdjuster
Report1.Database.SetDataSource rstCurrent
frmReport.crvCommon.ReportSource = Report1
frmReport.crvCommon.ViewReport
frmReport.crvCommon.Visible = True
frmReport.Show
Exit Sub
hi dcarlson,
what u mean by using the report designer component within VB?
I already set the report layout using crystal report v7.0 and what can i do so that is can print preview the report for certain records only in VB?
I don't create reports through Crystal Reports Itself. When you're in VB click on project then Add Crystal Report. This will allow you to create a Crystal Report using the crystal report designer component. After you've created your report use the code that I posted in this thread. There should be some sample under your crystal reports folder. Otherwise you can try the code that Yoya posted.
Check this out.
http://support.seagatesoftware.com/e.../tutorials.asp