Results 1 to 5 of 5

Thread: How can I pass a parameter to Crystal Report 5 from Visual Basic Screen?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Windsor
    Posts
    100

    How can I pass a parameter to Crystal Report 5 from Visual Basic Screen?

    I am using Crystal Report 5 with Visual Basic 6. I like a use select a data from Visual Basic Screen and list value in the VB report, based on the selection. How can I pass a parameter to Crystal Report 5 from Visual Basic Screen?

  2. #2
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Albany, NY
    Posts
    489
    Report.RecordSelectionFormula =

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Windsor
    Posts
    100

    Where can I put this code?

    Where can I put this code?
    How can I specify the passed value parameter?

  4. #4
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Albany, NY
    Posts
    489
    This is an example i use in one of my programs.
    Most of the code has to do with calculating the formula
    all you need is to put that Report.ReportSelectionFormula =
    into the formload event on your form that displays the
    report.

    VB Code:
    1. Dim Report As New CrystalReport1
    2.  
    3. Private Sub Form_Load()
    4.  
    5. Screen.MousePointer = vbHourglass
    6.  
    7. '***************** Get Date from List and Reorder for Year/Month/Day ************
    8. Dim TheDate, strYear, strMonth, strDay, CrystalParameter As String
    9. Dim Index As Integer
    10. Dim numYear, numMonth, numDay
    11. TheDate = ""
    12. CrystalParameter = "{dtcelluse.dteDate} = date("
    13.  
    14. Index = 0
    15.  
    16. Do While Index < Reports.List1.ListCount
    17.     If Reports.List1.Selected(Index) Then
    18.         numYear = Year(Reports.List1.List(Index))
    19.         numMonth = Month(Reports.List1.List(Index))
    20.         numDay = Day(Reports.List1.List(Index))
    21.         If TheDate <> "" Then
    22.             TheDate = TheDate & " OR " & CrystalParameter & numYear & "," & numMonth & "," & numDay & ")"
    23.         Else
    24.             TheDate = CrystalParameter & numYear & "," & numMonth & "," & numDay & ")"
    25.         End If
    26.     End If
    27.     Index = Index + 1
    28. Loop
    29.  
    30. 'Here is the Important Stuff
    31. Report.DiscardSavedData     'Gets rid of REFRESH problem
    32. Report.RecordSelectionFormula = TheDate 'Gives Selection Parameter
    33.  
    34. CRViewer1.ReportSource = Report
    35. CRViewer1.ViewReport
    36. Screen.MousePointer = vbDefault
    37.  
    38. End Sub
    Last edited by jcfowl; Feb 1st, 2002 at 01:46 PM.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Windsor
    Posts
    100
    Thank you very much JCfowl

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