borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Coding in Crystal Report)Next Topic (Edit a RPT in Runtime on VB.NET) New Topic New Poll Post Reply
AndreaVB Forum : Reporting tools : Filter records
Poster Message
punkzappa
Level: Trainee

Registered: 26-04-2005
Posts: 2

icon Filter records

hi i'm new to vb programming and crystal report. im working on an employee database and i want to be able to generate a report for a specific person only, depending on their id number. i tried using SQL Select function but still it generates the report for all the employees. here is my code:

Dim rsreport as New ADODB.Recordset
Dim Report As New CrystalReport1
Dim WithEvents sect As CRAXDRT.Section

Private Sub Form_Load()

    rsreport.Open "SELECT * FROM Employee WHERE idno='" & frmMain.txtidno.Text & "'", mydb, 1, 2
    Report.Database.SetDataSource rsreport

    Set sect = Report.Sections("Section5")
    
    CRViewer1.ReportSource = Report
    CRViewer1.ViewReport
    CRViewer1.Zoom 1
End Sub

Private Sub Form_resize()
    CRViewer1.Top = 0
    CRViewer1.Left = 0
    CRViewer1.Height = ScaleHeight
    CRViewer1.Width = ScaleWidth
End Sub


Private Sub sect_format(ByVal pFormattingInfo As Object)
Dim bmp As StdPicture

With sect.ReportObjects
    Set bmp = LoadPicture(App.Path & "\images\" & .Item("Field22").Value)
    Set .Item("Picture2").FormattedPicture = bmp
End With
    
End Sub


Many thanks!
  

29-04-2005 at 01:51 PM
View Profile Send Email to User Show All Posts | Quote Reply
Goran
Level: Moderator

Registered: 16-05-2002
Posts: 1681
icon Re: Filter records

There are two ways I know it can be done... If you are using this recordset only for passing it to CR, then you my avoid extra overheat (due to creating this ADO recordset), and use RecordSelectionFormula property of report object. Example:

Dim CRXApp As New CRAXDRT.Application
Dim rpt As CRAXDRT.Report

    Set rpt = CRXApp.OpenReport(App.Path & "\Reports\" & rptName, 1)

    rpt.RecordSelectionFormula = "{Employee.idno}='" & frmMain.txtidno.Text & "'"

    CR.ReportSource = rpt
    CR.ViewReport


To do it using recordset, as you have tried

Dim CRXApp As New CRAXDRT.Application
Dim rpt As CRAXDRT.Report
Dim CRXDatabase As CRAXDRT.Database

    Set rpt = CRXApp.OpenReport(App.Path & "\Reports\" & rptName, 1)

    Set CRXDatabase = rpt.Database
    CRXDatabase.SetDataSource rs, 3, 1

    CR.ReportSource = rpt
    CR.ViewReport



____________________________
If you find the answer helpful, please mark this topic as solved.
29-04-2005 at 03:36 PM
View Profile Send Email to User Show All Posts | Quote Reply
punkzappa
Level: Trainee

Registered: 26-04-2005
Posts: 2
icon Re: Filter records

ei man ur the best. i did the first one and it works! ur such a big help. keep it up!  

03-05-2005 at 12:53 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : Reporting tools : Filter records
Previous Topic (Coding in Crystal Report)Next Topic (Edit a RPT in Runtime on VB.NET) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder