Results 1 to 7 of 7

Thread: crystal report help

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    Penang, Malaysia
    Posts
    51

    Red face

    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)

  2. #2
    Junior Member
    Join Date
    Aug 2000
    Location
    Nuevo Laredo, Tamps. Mexico
    Posts
    21
    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
    Yoya Lozano

  3. #3
    Hyperactive Member Asaf_99's Avatar
    Join Date
    Jul 2000
    Location
    Israel
    Posts
    335
    What does the Crystal Reports do anyway?
    Asaf Sagi

    ICQ: 61917199
    E-Mail: [email protected]

  4. #4
    Hyperactive Member
    Join Date
    Apr 2000
    Location
    Sudbury, Ontario, Canada
    Posts
    274
    If you're using the report designer component within VB here's a way to set a recordset to a report.
    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
    Hope this helps.


  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    Penang, Malaysia
    Posts
    51
    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?

  6. #6
    Hyperactive Member
    Join Date
    Apr 2000
    Location
    Sudbury, Ontario, Canada
    Posts
    274
    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.

  7. #7
    Hyperactive Member
    Join Date
    Apr 2000
    Location
    Sudbury, Ontario, Canada
    Posts
    274

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width