Hey guys!

I'm almost done with a payroll application im creating but I'm stuck with this Crystal Reports issue.I want to filter the report by displaying data by two specific textbox,TextboxA(EmployeeID) and textboxB(PayrollNumber).How can I do this?please help!!

Recommended Answers

All 13 Replies

I'm using this code in my form load event...

Dim crptdoc As New ReportDocument
        crptdoc.Load("path where your rpt file is")

        Dim myDS As New DataSet
        crptdoc.SetDataSource(myDS.Tables("soruce table name"))
        Dim mystr As String
        mystr = "{tablename.EmployeeID} = '" & textboxA.text & "'  and {tablename.PayrollNumber} = '" & textboxB.text & "'"

        CrystalReportViewer1.SelectionFormula = mystr
        CrystalReportViewer1.ReportSource = crptdoc

I hope it helps...

I'm using this code in my form load event...

Dim crptdoc As New ReportDocument
        crptdoc.Load("path where your rpt file is")

        Dim myDS As New DataSet
        crptdoc.SetDataSource(myDS.Tables("soruce table name"))
        Dim mystr As String
        mystr = "{tablename.EmployeeID} = '" & textboxA.text & "'  and {tablename.PayrollNumber} = '" & textboxB.text & "'"

        CrystalReportViewer1.SelectionFormula = mystr
        CrystalReportViewer1.ReportSource = crptdoc

I hope it helps...

Thanx for the reply gerchi!But im still getting an error.It says "Number is required here"..I forgot to tell you im using VB.NET with an Access database.

@acepeda Will you please post your code?

@acepeda Will you please post your code?

I really have no code as of now,I have tried everything!I only have the two textbox and search button.sorry if this doesn't help much!

Dear acepeda

gerchi152 give you code for that and you say you dont have code so just try his/her code. And then if you are getting error please post where u get that by debugging it....

well if you are getting this error then little bit change your code like this

mystr = "{tablename.EmployeeID} = " & val(textboxA.text) & "  and {tablename.PayrollNumber} = " & val(textboxB.text)

hope this will help you , and please post your code after getting some error so that any one can better help you.

Regards

Dear acepeda

gerchi152 give you code for that and you say you dont have code so just try his/her code. And then if you are getting error please post where u get that by debugging it....

Yes I tried gerchi's code and got the error when pressed the search button.I entered the code as he said in the form load.I call the form with the search button.

I think waqasas....... is right...

Id might be in Numeric value so no need of ''.

Just remove and try again...

I think waqasas....... is right...

Id might be in Numeric value so no need of ''.

Just remove and try again...

Ok Guys so I tried the code with just filtering the EmployeeID and it works great but when I tried with PayrollID it says "A String is required here"..any thoughts?

Please first post your table structure..

Field Name - Data Types

Im able to view Data from the EmployeeID I enter but its not filtering my second textbox.Its displaying all data from Employee.What am I doing wrong?

Im able to view Data from the EmployeeID I enter but its not filtering my second textbox.Its displaying all data from Employee.What am I doing wrong?

hello !
please check this post carefully ,

mystr = "{tablename.EmployeeID} = " & val(textboxA.text) & "  and {tablename.PayrollNumber} = '" & textboxB.text &"'"
'first check you database fields data type , if your field datatype is int , bigint , decimal etc then always use val(your textbox or variable ) and if datatype is string , char , or varchar , then always use 'your textbox or variable' , now you should have these things in your mind before coding.

Hope next time your prob will be different not regarding with datatype .
if this post solve your prob and useful for you , please vote me up .

Regards

hello !
please check this post carefully ,

mystr = "{tablename.EmployeeID} = " & val(textboxA.text) & "  and {tablename.PayrollNumber} = '" & textboxB.text &"'"
'first check you database fields data type , if your field datatype is int , bigint , decimal etc then always use val(your textbox or variable ) and if datatype is string , char , or varchar , then always use 'your textbox or variable' , now you should have these things in your mind before coding.

Hope next time your prob will be different not regarding with datatype .
if this post solve your prob and useful for you , please vote me up .

Regards

Ok everything is working great but now theres a new problem!Its displaying the data twice.Whats wrong now?this is my code:

Dim crptdoc As New CrystalReport1
        Dim mystr As String
        Dim myDS As New DataSet1

        crptdoc.Load("C:\Users\ACP\Documents\Visual Studio 2005\Projects\Sistema ManoObras\SistemaManoObras\SistemaManoObras")
        crptdoc.SetDataSource(myDS.Tables("Payroll"))

        mystr = "{Employees.EmployeeID} = " & Val(Form1.TxtEmpID.Text) & "and {Payroll.PayrollID} = " & Val(Form1.TxtPayrollID.Text) & ""
       
 CrystalReportViewer1.SelectionFormula = mystr
        CrystalReportViewer1.ReportSource = crptdoc
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.