Results 1 to 10 of 10
  1. #1
    archie is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    26

    How do you filter report?


    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.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The OpenReport command has a WhereCondition argument that applies a filter to the report RecordSource.

  3. #3
    archie is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    26
    um.. you mean a code? can u give me a simple example?

    thanks

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Have you looked in VBA Help under OpenReport yet?

  5. #5
    archie is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    26
    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

  6. #6
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    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

    Code:
    Dim StrFilter As String
    Next your combo box provides the criteria for the filter. This is gleaned from the after update event or the control

    Code:
    StrFilter = "[StudentID]=" & Me.CboStudents
    Where StudentID is the name of the Primary Key field in the reports underlying table/query.

    Where Me.CboStudent is the contents of the bound column in your combo box.

    This would actuall be translated as

    Code:
    [StudentID]=21
    So when you want to print the report you would code it as such

    Code:
    DoCmd.OpenReport "Student_report", acViewNormal, StrFilter
    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.

    David

  7. #7
    archie is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    26
    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 question and thank you for your time

  8. #8
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    Can you post a copy of your mdb

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The WhereCondition argument is the 4th argument, not the 3rd.
    DoCmd.OpenReport "Student_report", , , StrFilter

  10. #10
    archie is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    26
    thank you very much guys, it works!!!
    you guys are the best


    good day
    archie

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Combo Box Filter
    By jgelpi in forum Programming
    Replies: 3
    Last Post: 07-27-2009, 12:54 PM
  2. filter by the number of character
    By bangemd in forum Access
    Replies: 1
    Last Post: 06-30-2009, 10:33 AM
  3. Using Access for an Excel like filter?
    By crownedzero in forum Queries
    Replies: 0
    Last Post: 06-15-2009, 01:55 PM
  4. Applying a filter to a combo box
    By bugchaser in forum Programming
    Replies: 1
    Last Post: 02-20-2009, 02:37 PM
  5. Newbie filter question
    By benplace in forum Access
    Replies: 1
    Last Post: 12-03-2005, 08:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums