Results 1 to 6 of 6

Thread: Crystal Report In VB

  1. #1

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Thumbs up Crystal Report In VB

    Hi all
    Often user get problem when they make setup of the VB project using the crystal report.
    Report will be not display at the other Pc where crystal report is not installing.

    1) How to use the crystal report
    Make the report it is batter fro you that you make it using the DSN with the database.
    For making the run time DSN you can use the code given by me in the VB
    Code Bank in the General problem for the new user, See my Signature.

    Open the Project Add the crystal report control

    Right click on this control and set the property.

    Report for the string value in the database

    VB Code:
    1. Private Sub Command1_Click()
    2. 'Report With String
    3. Dim S As String
    4. S = "{Table.Field}='" & Text1.Text1 & "'"
    5. With CrystalReport1
    6.     .ReportFileName = App.Path & "\ReportName.rpt"
    7.     .SelectionFormula S
    8.     .Action = 1 'Will Show The Report
    9. End With
    10. End Sub

    Report for the integer value in the database

    VB Code:
    1. Private Sub Command1_Click()
    2. 'Report With Number
    3. Dim S As String
    4. S = "{Table.Field}=" & Text1.Text1 & ""
    5. With CrystalReport1
    6.     .ReportFileName = App.Path & "\ReportName.rpt"
    7.     .SelectionFormula S
    8.     .Action = 1 'Will Show The Report
    9. End With
    10. End Sub

    Report when there is mix of number and the integer in the condition

    VB Code:
    1. Private Sub Command1_Click()
    2. 'Report With Number and string
    3. Dim S As String
    4. S = "{Table.Field}=" & Text1.Text1 & " and {Table.Field}='" & Combo1.Text & "'"
    5. With CrystalReport1
    6.     .ReportFileName = App.Path & "\ReportName.rpt"
    7.     .SelectionFormula S
    8.     .Action = 1 'Will Show The Report
    9. End With
    10. End Sub

    For removing the error at the client Pc add the Dll database.dll, crystal32.ocx,p2sodbc.dll
    You can change the selection formula according to above condition
    Here table is the TableName
    Field is the Table Field
    Report Is the Crystal Report Name

    Last edited by shakti5385; Oct 7th, 2006 at 08:21 AM. Reason: Add VBCODE

  2. #2

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Crystal Report In VB

    When There is need to find the report between two date

    VB Code:
    1. Private Sub Command1_Click()
    2. 'Report Between Two Date
    3. Dim S As String
    4. S = "{Table.DateField}>=date( " & DTPicker1.Year & "," & DTPicker1.Month & "," & DTPicker1.Day & ") And {Table.DateField}<= date(" & DTPicker2.Year & "," & DTPicker2.Month & "," & DTPicker2.Day & ")"
    5. With CrystalReport1
    6.     .ReportFileName = App.Path & "\ReportName.rpt"
    7.     .SelectionFormula S
    8.     .Action = 1 'Will Show The Report
    9. End With
    10. End Sub

  3. #3

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Thumbs up Re: Crystal Report In VB

    Using the selection formula we have one more option for searching the report using our condition, this option is call SQL query option using this option you are able to pass your query in the report and the report will show the selected data using the query. SQL selection query example is given below.
    Here table is the table name and field is the field in the table. You can change the Query according to the condition.
    Here for sorting the data you can also use the order by clause.
    See the Example.

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim S As String
    3. S = "Select * from Table where field='" & Text1.Text & "' Order By ID"
    4. With CrystalReport1
    5.     .ReportFileName = App.Path & "\ReportName.rpt"
    6.     .SQLQuery = S
    7.     .Action = 1
    8.  [B]MsgBox .RecordsPrinted 'For Total number of record[/B]
    9. End With
    10. End Sub
    Last edited by shakti5385; Oct 9th, 2006 at 09:13 AM.

  4. #4
    New Member
    Join Date
    Jan 2007
    Posts
    8

    Re: Crystal Report In VB

    sir, this is my code in VB6 crustal reports XI

    Private Sub Form_Load()
    Dim crxApp As New CRAXDDRT.Application
    Dim crxReport As CRAXDDRT.Report
    Dim ReportName As String

    ReportName = App.Path & "\report1.rpt"
    Set crxReport = crxApp.OpenReport(ReportName)
    CRV1.ReportSource = crxReport

    Dim S As String
    ' i want to view only transactions under CustSaleNo = 1. don't have selectionFormula Method/Property
    S = "{CustomerInvDetails.CustSaleNo} <> '1'"
    crxReport.RecordSelectionFormula = S <----error here "A number is required in here"

    CRV1.ViewReport

    End Sub

  5. #5
    New Member
    Join Date
    Jan 2007
    Posts
    8

    Re: Crystal Report In VB

    fix my error... there should be no ' '...it should only be 1 without the ' "

  6. #6

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Smile Re: Crystal Report In VB

    Quote Originally Posted by eureka8888
    fix my error... there should be no ' '...it should only be 1 without the ' "
    Post this problem in the reporting section, not in the tutorial.
    Thanks

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