Results 1 to 9 of 9
  1. #1
    SunTop is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Aug 2016
    Posts
    93

    Subform filter


    Hello everyone

    On my database I have a form and on this form I have a text box, a list box and a subform. On the subform I have two combo boxes and a text box and the subform is set to datasheet view. The list box on the main form is unbound and I use it to filter the underlying query for the row source of the two combo boxes on the subform. The main form has a one to many relation with the subform. I also have an onclick event on my list box to filter the combo boxes on my subform if I needed to enter more than one record on my subform. So the process goes as follows:

    Starting with the main form:
    1. Enter a value on the text box
    2. Pick a value on the unbound list box to filter the two combo boxes on the subform

    Moving to the subform:
    1. pick a value for the two combo boxes
    2. enter a value for the text box

    Now here is what I am facing an issue with:
    Suppose now I needed to enter another record on the subform, I would have to move back to the main form to select another value from the list box to filter the underlying query of the two combo boxes on the subform. When I do that and the onclick event fires up, the datasheet on my subform looks really awkward. The columns for the two combo boxes are empty now, but the value on the text box is still there. This confuses the user. Now the user does not know where to enter the new record. How can I filter the underlying query of the combo boxes on the subform and keep the previously entered data ?

  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,931
    This is a well-known and often discussed issue. Here is one https://www.accessforums.net/showthread.php?t=65938
    Dependent comboboxes displaying lookup alias just do not work nice with continuous or datasheet forms. There is no perfect solution.
    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
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    your issue is akin to cascading combos in a continuous form. You need a 'default' rowsource for your combos to select everything e.g.

    SELECT ID, Name from myTable

    then in the combo enter event put the following code (change names to suit)

    combo1.rowsource="SELECT ID, Name from myTable WHERE somevalue=[parent].
    [listboxname]"

    and in the exit event
    combo1.rowsource="SELECT ID, Name from myTable"

    do not have any code in your listbox afterupdate event that affect the combo rowsources or requeries the subform

  4. #4
    SunTop is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Aug 2016
    Posts
    93
    Thanks for your replay June7,Ajax I have read the thread that June7 linked on his post and I have tried the method Ajax suggested. I have been tackling this issue for two days now, but no luck. I have attached a sample database, I hope somebody takes a look at it and tell me what am I doing wrong ?
    Attached Files Attached Files

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    I think the problem is that the rowsource is referencing a control outside of the existing record which is why it is not working as expected. Also if the user goes from the product control to the listbox by using the mouse the lostfocus/exit events for the product control are not triggered. You have also not referenced the listbox as I said, you are using forms!form. rather than parent.

    I don't have time to figure out a solution right now. It may be that you need also need to apply the 'default' code to the listbox enter or gotfocus event.

  6. #6
    SunTop is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Aug 2016
    Posts
    93
    Thanks for your replay Ajax,

    I hope that you look at it again when you have some free time.

  7. #7
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    It might be better to use a continuous subform. See attached db
    Attached Files Attached Files
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    it may be a while - my paying clients have to come first.

    The principle is right, but needs some experimenting to find the right events to trigger

  9. #9
    SunTop is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Aug 2016
    Posts
    93
    Thanks Bob Fitz for your replay

    The attached db on your pervious post is pretty close to what I want (putting a text box on a combo box was very smooth by the way, it made me scratch my head for a while wondering why a text box is behaving like a combo box). However, you have removed the List box on the main form, which I need for two reasons:

    • In my actual database I have many regions and I use a text box together with the list box to search for the region (search as you type) and then I use the list box to filter the combo box region
    • I also use the value on the list box to be the source of an image control on the main form

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

Similar Threads

  1. Replies: 1
    Last Post: 12-05-2016, 02:23 PM
  2. Replies: 13
    Last Post: 03-09-2014, 02:11 AM
  3. Replies: 1
    Last Post: 08-16-2012, 01:51 PM
  4. Replies: 6
    Last Post: 05-05-2012, 08:43 AM
  5. Pass Subform filter to subform in report
    By camftm in forum Programming
    Replies: 16
    Last Post: 07-19-2011, 07:12 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