Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    zerokono is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    8

    Filtering a filtered subform!

    please be patient!!!, I am totally new to access....

    here is my problem. I have a main form <frmmaindata> with a combobox <Combo3>. When I select an item from the combobox there is a subform <tblreceipts> which correctly filters based on the item selected from the combobox <this happens via vba in the `OnChange' event procedure>. What I would like to do now is the problem..... Once the subform has filtered, I would also like to filter again <there is a textbox <transactiontype> which has various text in such as RECEIPTS, USAGE, TRANSFER etc. What I need is to filter the subform again to display RECEIPTS or can I do this in 1 action via the combobox? This may be a `so simple' fix but as I said I am `very new' to access and cant figure it out. Thanks in advance everyone.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Exactly how are you using combobox to filter subform - VBA code or dynamic parameterized query? Review http://allenbrowne.com/ser-62.html
    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
    zerokono is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    8
    Private Sub Combo3_Change()
    Dim StrFilter As String
    StrFilter = "materialdescription=" & Me.Combo3
    Forms!frmmaindata!tblreceipts.Form.Filter = StrFilter
    Forms!frmmaindata!tblreceipts.Form.FilterOn = True
    End Sub

    Jonarve Limited1.zip

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,913
    So in the AfterUpdate of your control, test if anything is there, then add to filter?
    Something along the lines of

    Code:
    Dim strFilter As string
    If Len(Me.txtControl ) > 0 Then
        strFilter = Me.Filter & " AND TransactionType = '" & Me.TransactionType & "'"
        Me.Filter = strFilter
    End If
    That assumes code is in the form.
    Not sure if you have to switch off the filteron and back on again?

    HTH
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    zerokono is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    8
    Hi, thanks for the reply...

    I put the code in the AfterUpdate of the control but get method or data member not found

    are you suggesting that once the OnChange event has occurred I should code the AfterUpdate

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,913
    Quote Originally Posted by zerokono View Post
    Hi, thanks for the reply...

    I put the code in the AfterUpdate of the control but get method or data member not found

    are you suggesting that once the OnChange event has occurred I should code the AfterUpdate
    I am saying once, you enter something in your transactiontype control, then that code should run when it has been updated? You could also use the LostFocus event as well?
    YOU have to get the names correct?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    zerokono is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    8
    if im understanding you correctly, that's not what i was after. When i select an item from the combobox in the main form, I want it to display the items selected and then I want to re-filter the subform to display all those items which have a transactiontype called RECEIPT.

    Cheers

  8. #8
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,788
    Basically, you cannot filter a filter. You would need to set the filter conditions for situation A and apply. If you take some other action and wish to filter further (situation B), you must reconstruct the filter for A+B and then reapply the filter. If what you're saying is that you want to ignore A and use only B filter, then you alter the filter code to suit only B and then reapply.

    IMO you should use a combobox instead of a textbox to enter the second filter parameter. Any typos are likely to produce no records based on erroneous input. However, if you want to filter the subform as you type, then you'd need to use the OnChange event of your textbox. I wont' have time to download and play with your db right now so hopefully that helps a bit.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,913
    Quote Originally Posted by zerokono View Post
    if im understanding you correctly, that's not what i was after. When i select an item from the combobox in the main form, I want it to display the items selected and then I want to re-filter the subform to display all those items which have a transactiontype called RECEIPT.

    Cheers
    My understanding was you wanted to filter on the combo, then you want to filter further with a transaction type?
    If it is one or the other, then just set the filter as required. Much easier. one will overwrite the other.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Could you please try this:
    Code:
    Private Sub Combo3_AfterUpdate()
    Dim StrFilter As String
    StrFilter = "materialdescription=" & Me.Combo3 & " AND [transactiontype]='RECEIPT'"
    Forms!frmmaindata!tblreceipts.Form.Filter = StrFilter
    Forms!frmmaindata!tblreceipts.Form.FilterOn = True
    End Sub
    You want the code to be in the AfterUpdate instead of the Change event because the later fires for every keystroke.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  11. #11
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,563
    I think it would be best if you explain what your business process is.

    It looks to me like you want your tblInventory as a Main Form with a Subform to control Receipts.

    If this is the case you need to get rid of ALL of the Lookup fields in your tables. These are a NO NO in access.
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  12. #12
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    I agree with Mike. It seems all responses are guessing what the OP is doing and/or wants.

    @zerokono
    if im understanding you correctly, that's not what i was after. When i select an item from the combobox in the main form, I want it to display the items selected and then I want to re-filter the subform to display all those items which have a transactiontype called RECEIPT.
    It would be helpful to you and readers if you could tell us in non-database terms WHAT you are trying to automate in plain English. Once readers understand WHAT your requirement is, then options and alternatives as to HOW it may be done using Access will follow.

  13. #13
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Naming consistency???

    Quote Originally Posted by zerokono View Post
    I have a main form <frmmaindata>
    with a combobox <Combo3>.
    When I select an item from the combobox there is a subform <tblreceipts>
    You have a form with the name tblreceipts? Shouldn't the name be frmreceipts? Or sfrmreceipts??

    Confusing

    Also, you should be using the combo box "AfterUpdate" event, NOT the "OnChange" event. See Help for the "OnChange" event.....

  14. #14
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,913
    Quote Originally Posted by ssanfu View Post
    Naming consistency???


    You have a form with the name tblreceipts? Shouldn't the name be frmreceipts? Or sfrmreceipts??

    Confusing

    Also, you should be using the combo box "AfterUpdate" event, NOT the "OnChange" event. See Help for the "OnChange" event.....
    Sadly, the wizard names the form by default after the source object.
    If a person knows no better, they will likely just accept it, when they save the form.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  15. #15
    zerokono is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    8
    thats it!!!!!

    thank you so much, its exactly what I was looking for - perfect

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. FIltered Report based on filtered SubForm
    By Misterpokey in forum Programming
    Replies: 1
    Last Post: 03-16-2020, 08:27 AM
  2. filtered listbox on subform
    By ebjers in forum Forms
    Replies: 5
    Last Post: 07-15-2018, 11:19 AM
  3. Filtered subform to table
    By MTSPEER in forum Programming
    Replies: 2
    Last Post: 02-09-2016, 02:17 PM
  4. Filtering An Already Filtered Form
    By alsoto in forum Forms
    Replies: 3
    Last Post: 09-25-2012, 02:53 PM
  5. DCount on filtered subform
    By TheShabz in forum Forms
    Replies: 2
    Last Post: 07-13-2011, 02:22 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