Results 1 to 6 of 6
  1. #1
    epardo87 is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Dec 2016
    Posts
    101

    Optional query filter criteria


    Hello All,

    I have a query that needs to be able to filter a single column through two different forms, I'm thinking to use an IIF function in the critaria field based on wether one form is loaded or not. this is the formula I did but it doesn't work

    IIf([Forms]![frm22SelectStation].[IsLoaded],[Forms]![frm23StationDetail]!
    [List13]
    ,[Forms]![frm30UserData]!
    [List31]
    )

    any suggestions?

    thanks for your time!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    This idea fails if both are open.
    just make 2 queries. 1 for each form.

  3. #3
    epardo87 is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Dec 2016
    Posts
    101
    Quote Originally Posted by ranman256 View Post
    This idea fails if both are open.
    just make 2 queries. 1 for each form.
    Thanks for your response,

    I actually did that, the problem is that I have a series of forms which filter information in cascade as you go from one to another.
    • form 1 filters query 1 and opens form 2 which shows the filtered data in query 1
    • form 2 filters query 2 and opens form 3 which shows the filtered data in query 2
    • form 3 filters query 3 and opens form 4 which shows the filtered data in query 3


    now I need that form can 4 filter again query 2 and open form 3 showing the new filtered data in query 2. I need this loop to happen, and by having this conditional I believe the loop is solved. I would add an event so that before form 4 filters query 2, it first closes form 2 and vice-versa, this way the condition would work,Otherwise I'd have to create a lot of alternative queries and forms to open up if they move through it...

    I'm open to other alternatives, but the main goal is to have that loop possible.

  4. #4
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    When I need a common field I add that field to my main form which is always open. If you don't have a main form that is always open, create one and have it hidden. Then on the subsequent forms in the AfterUpdate I populate the field on the main form. My query will then read that field instead of worrying about which form it came from.

  5. #5
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,471
    Good suggestion aytee111, another variation might be to create a hidden field on each form and pass the criteria value to the new form after you open it and before you close the previous one. Then your info on the current form is based on that field.

    Also seems like a lot of forms opening/closing. Is it possible to just have 1 form with multiple criteria for filtering the data?

  6. #6
    epardo87 is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Dec 2016
    Posts
    101
    Thanks for your answers,

    at the end I used only two froms, the firstone with 3 combobox cascades, one listbox, and the second one with a listbox only, using this code I was able to make the forms loop the way I needed:

    Code:
    Private Sub btnStation_Click()
        Dim AreaLookUp As String
          AreaLookUp = DLookup("Area", "Qry-xreference", "StationDescription='" & Forms!frm30UserData!lstStation & "'")
        [Forms]![frm20MainStatus]![cmbArea] = AreaLookUp
        Dim SubLookUp As String
          SubLookUp = DLookup("[Subarea]", "[Qry-xreference]", "[StationDescription]='" & [Forms]![frm30UserData]![lstStation] & "'")
        [Forms]![frm20MainStatus]![cmbSub] = SubLookUp
    [Forms]![frm20MainStatus]![cmbStation] = [Forms]![frm30UserData]![lstStation] & ""
    [Forms]![frm20MainStatus].Refresh
    End Sub

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

Similar Threads

  1. Optional Multiple Criteria for SQL String
    By Markb384 in forum Queries
    Replies: 1
    Last Post: 10-29-2014, 06:26 AM
  2. Replies: 4
    Last Post: 08-08-2013, 12:10 PM
  3. Replies: 2
    Last Post: 10-23-2012, 12:18 PM
  4. Filter Report by Optional Date Range and Combo Box
    By ARickert in forum SQL Server
    Replies: 3
    Last Post: 10-17-2012, 10:46 AM
  5. multiple optional criteria
    By TheShabz in forum Programming
    Replies: 7
    Last Post: 07-05-2011, 05:13 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