good day my friend,
i just want to know how will i filter the result of reports in access. i want to create a combo/list box that when i select one data, it will print all the information regarding to that.
thank you very much and good day.![]()
good day my friend,
i just want to know how will i filter the result of reports in access. i want to create a combo/list box that when i select one data, it will print all the information regarding to that.
thank you very much and good day.![]()
Last edited by archie; 08-26-2009 at 02:11 AM.
The OpenReport command has a WhereCondition argument that applies a filter to the report RecordSource.
um.. you mean a code? can u give me a simple example?
thanks
Have you looked in VBA Help under OpenReport yet?
thanks for the link. but, how do i make a combo box that if i select 1 student and hit a command button, it will view/print all his related information? i tried the example code in the vb and replace it with the student_report. but, instead of printing 1 student, it just prints all the students records in my database... ouch
here the code that i tried and put it in the command button.
"DoCmd.OpenReport "Student_report", acViewNormal, "Report Filter"
thanks
archie
Archie,
Your are not clearly understanding the principle of filtering properly. On your form you will be defining who you want to print out the report for. This will be in the form of a filter string.
First you create a string variable to hold the filter string
Next your combo box provides the criteria for the filter. This is gleaned from the after update event or the controlCode:Dim StrFilter As String
Where StudentID is the name of the Primary Key field in the reports underlying table/query.Code:StrFilter = "[StudentID]=" & Me.CboStudents
Where Me.CboStudent is the contents of the bound column in your combo box.
This would actuall be translated as
So when you want to print the report you would code it as suchCode:[StudentID]=21
Alternatively you can look at the sample database I included on this forum abount using public variables. It comes with full documentation in a step by step manner.Code:DoCmd.OpenReport "Student_report", acViewNormal, StrFilter
David
thank you for the reply sir.
i tried it and follow the code you provided but, its still prints all the students
this is what i did in the cmdprint:
Private Sub cmdprint_Click()
Dim StrFilter As String
StrFilter = "[Studentid]=" & Me.Combo70 ////where my combo box is combo70 and its shows "1"
DoCmd.OpenReport "student_report", acViewNormal, StrFilter //// for the printing
End Sub
the way i see it, it must only print the student ID "1" . but ,why is it printing all of the students?
very sorry for the noob questionand thank you for your time
![]()
Can you post a copy of your mdb
The WhereCondition argument is the 4th argument, not the 3rd.
DoCmd.OpenReport "Student_report", , , StrFilter
thank you very much guys, it works!!!
you guys are the best
good day
archie