Results 1 to 7 of 7
  1. #1
    mortonsafari is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2015
    Location
    Brisbane, Queensland, Australia
    Posts
    39

    Report Pop-Up Filter question

    I have a report that filters the information within it by means of a ‘pop-up’ form filter.
    It currently contains two combo boxes as [Filter1] (Postcode) and [Filter2] (Suburb).
    It works great when just processing one field at a time eg. Postcode or Suburb, where only one value is filtered for. Both these fields are ‘text’ Data Types.

    The ‘Set Filter’ button runs the following code:-
    Private Sub b_Set_Click()
    Dim strSQL As String, intCounter As Integer
    'Build SQL String
    For intCounter = 1 To 2
    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) - 4))
    'Set the Filter property
    Reports![Contacts].Filter = strSQL
    Reports![Contacts].FilterOn = True
    End If
    End Sub

    I want to add/include two more Filter combo boxes – [Filter3] (from Postcode) and [Filter4] (to Postcode) - to allow for searching between Postcode values eg. Postcode >= [Filter3] (say 4000) AND <=[Filter4] (say 4300).
    In a query I would use in the Postcode field : >=[Filter3] And <=[Filter4] and it would then provide pop-ups asking for Parameter values for [Filter3] And [Filter4].

    In the pop-up filter form for the report I have the After Update for [Filter3] set as:
    Private Sub Filter3_AfterUpdate()
    Me.Filter4.Requery
    End Sub
    which resets the values in combo box [Filter4] at values greater than the [Filter3] value selected.
    The user can then select a value in combo box [Filter4] which is greater than the value selected in combo box [Filter3].

    The user would select either [Filter1]:Postcode OR [Filter2]:Suburb OR [Filter3]:from Postcode AND [Filter4]:to Postcode.

    I now am having problems getting the code right so that I can use the four [Filters] on the form and have the report filtered according to the para above.

    What would I need to include in the Private Sub b_Set_Click() code to allow thing to work as I would like.

    Any assistance appreciated.


    mortonsafari

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,901
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    mortonsafari is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2015
    Location
    Brisbane, Queensland, Australia
    Posts
    39
    Thanks. I'll check things out and see what I can do.
    Appreciate your help. Thanks again.

  4. #4
    mortonsafari is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2015
    Location
    Brisbane, Queensland, Australia
    Posts
    39
    That link was useful in showing how to do a number of things, but it didn't really address my issue where I have two references to the same field eg. Postcode, where I am trying to do a '>= [value] and <= [value]' on the same field of Postcode.
    If anyone has ideas, shout them out.
    Many thanks
    mortonsafari

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,901
    Adapt the code. It has example for range criteria. Build the criteria as needed. Postcode is a text field?

    [Postcode] BETWEEN 'start value' AND 'end value'

    or

    [Postcode] >= 'start value' AND [Postcode] <= 'end value'
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    mortonsafari is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2015
    Location
    Brisbane, Queensland, Australia
    Posts
    39
    I have sorted out my problem with the 3rd and 4th combo boxes where I am using the >= AND <= Parameters using the same PostCode field and have changed the PostCode field to a Number and not text.

    Now the 1st combo box which is was using in the code originally posted is now numerical and the code for that section of the action is giving the error of "Data type mismatch in criteria expression".
    What changes would I need to make in the original code as shown at the start of this post to make it work.
    Also I probably need to put in a message so that it users select a value in both combos it pops up to say "Select either Postcode OR Suburb".

    Thanks everyone.

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,901
    Number field parameters do not use delimiters. Chr(34) is code for quote mark. The code is concatenating this as text delimiter. This would not be done for number field.

    Date fields would use # delimiter.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Simple Filter Question
    By cbende2 in forum Access
    Replies: 3
    Last Post: 05-20-2015, 10:02 AM
  2. Filter Question
    By data808 in forum Access
    Replies: 3
    Last Post: 07-02-2014, 02:11 AM
  3. Combbox / Filter Question
    By 82280zx in forum Programming
    Replies: 1
    Last Post: 03-16-2014, 04:07 PM
  4. Basic filter question... filter with like
    By Ruegen in forum Programming
    Replies: 9
    Last Post: 12-03-2013, 08:14 PM
  5. Another Search Filter Question
    By r0v3rT3N in forum Programming
    Replies: 4
    Last Post: 07-23-2012, 12:20 PM

Tags for this Thread

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