Results 1 to 4 of 4
  1. #1
    TubbzUK is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    3

    Filter Report by Form using combo boxes

    Hi,

    I have report that i want to filter by various different criteria.
    Say for example there is 5 different fields. If you select option 1 of filter 1 then click apply the report will only show all records that contain option1.
    If option 1 is blank and you select something in option 2, clcik apply and only option 2 will be shown. also if you select option 1 and option 2 click apply and only theose records matching both will be shown.

    I have searche dand found some code to help me with this.
    When i alter it to suit my database i get a "Enter Parameter" box appear and the report is blank with no records in view.
    I have filtered all of my combo boxes to display options taken from the database by the row source being a sql string SELECT DISTINCT [QC tasting].[Sample nature?] FROM [QC tasting];

    The code i have got on my apply button is

    Private Sub Apply_Click()
    Dim strSQL As String, intCounter As Integer
    'Build SQL String
    For intCounter = 1 To 5
    If Me("Filter" & intCounter) <> "" Then
    strSQL = strSQL & "[" & Me("Filter" & intCounter).Tag & "] " & " = " & Chr(34) & Me("Filter" & intCounter) & Chr(34) & " And "
    End If
    Next
    If strSQL <> "" Then
    'Strip Last " And "
    strSQL = Left(strSQL, (Len(strSQL) - 5))
    'Set the Filter property
    Reports![QC tasting].Filter = strSQL
    Reports![QC tasting].FilterOn = True
    End If
    End Sub

    ANy help would be great,

    regards,



    Alan

  2. #2
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    What field is the parameter looking for: Is there a typo somewhere such that Access is looking for a non-existing field. That is usually the cause of these situations. Does your query work if you take the sql statement to the QBE.

    BTW:

    If I were doing this, I would build the report off a query and use a form to generate the query and the report. Here are two examples of what I mean.

    http://www.datapigtechnologies.com/f...earchform.html

    and

    http://www.datapigtechnologies.com/f...mtoreport.html

  3. #3
    TubbzUK is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    3
    HI, thanks for your help,
    i am a complete novice though and do not get the sql statement to QBE bit.

    what do i need to do to do that?

    regards,

    Alan

  4. #4
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    You have built a query in VBA. All I am suggesting is create that same query using the same criteria and build it in the Query Builder and see if it works.

    Alan

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

Similar Threads

  1. code needed to filter form using combo boxes
    By drjim in forum Programming
    Replies: 1
    Last Post: 06-29-2012, 01:50 PM
  2. Replies: 4
    Last Post: 06-12-2012, 11:49 AM
  3. how to filter data using two combo boxes?
    By jasonix in forum Reports
    Replies: 3
    Last Post: 11-21-2011, 03:04 AM
  4. Filter based on two combo boxes.
    By jakeao in forum Programming
    Replies: 1
    Last Post: 05-22-2011, 10:56 AM
  5. Filter form from multiple combo boxes
    By Bird_FAT in forum Programming
    Replies: 6
    Last Post: 05-19-2010, 09:32 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