Results 1 to 13 of 13
  1. #1
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    154

    Using a subform within a form and displaying the results in the subform filtered by textbox value

    Hi,



    What am I trying to achieve
    I have a main form that contains a subform and I want the contents displayed inside the subform to be filtered by the value of a textbox in the main form.
    Main form = Form1
    Sub form = Subform1
    TextBox = Text1


    See picture below
    Click image for larger version. 

Name:	Capture6.PNG 
Views:	25 
Size:	23.4 KB 
ID:	52285


    Currently, my subform is not displaying anything, just comes up empty despite setting the parts I have marked in yellow in the photo below i.e. filtering the tblMovements by case id = value in text box 1

    Click image for larger version. 

Name:	Capture7.PNG 
Views:	25 
Size:	35.2 KB 
ID:	52286

  2. #2
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    Can you just set the Master/Child links in the subform control using CaseID?


    Click image for larger version. 

Name:	Screenshot 2024-10-10 141946.png 
Views:	26 
Size:	5.8 KB 
ID:	52287
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    Just do what Moke123 advises.
    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

  4. #4
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    154
    Quote Originally Posted by moke123 View Post
    Can you just set the Master/Child links in the subform control using CaseID?


    Click image for larger version. 

Name:	Screenshot 2024-10-10 141946.png 
Views:	26 
Size:	5.8 KB 
ID:	52287

    I tried your approach but still not working.


    In tblCases I have CaseID = 234

    Click image for larger version. 

Name:	Capture11.PNG 
Views:	19 
Size:	15.7 KB 
ID:	52288


    In tblMovements there are records for CaseID = 234

    Click image for larger version. 

Name:	Capture10.PNG 
Views:	18 
Size:	26.8 KB 
ID:	52289


    However, when I go to my main form (i.e. Form 1) and select that client who has CaseID = 234 the Audit Trail of Client comes back empty (i.e. the subform appears blank and weirdly just shows CaseID =1 regardless of which client is selected).

    Click image for larger version. 

Name:	Capture9.PNG 
Views:	18 
Size:	37.6 KB 
ID:	52290


    I would have expected it to show the records when you filter tblMovements for CaseID = 234


    Here is the form properties for my subform (i.e. frmCaseDetail) and you can see it is bounded to tblMovements

    Click image for larger version. 

Name:	Capture8.PNG 
Views:	18 
Size:	53.9 KB 
ID:	52291



    Click image for larger version. 

Name:	Capture7.jpg 
Views:	18 
Size:	129.5 KB 
ID:	52292



    And my main form is bounded to tblCases.
    The CaseID field in my tblCases is of the type AutoNumber and it set to Primary Key.
    The CaseID field in my tblMovements is of the type Number and it is not a Primary Key.
    I have defined a "One-to-Many" relationship between the two tables.

    Why is this not working then? I have I missed something?


    Thank You

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    Upload a sample db.
    If you need to hide the data use this
    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

  6. #6
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    154
    Following on from my last message, I just want to make it clear that that CaseID textbox inside my main form derives it value from the following vba code:

    Click image for larger version. 

Name:	Capture4.PNG 
Views:	18 
Size:	54.9 KB 
ID:	52293

    Click image for larger version. 

Name:	Capture5.PNG 
Views:	18 
Size:	3.6 KB 
ID:	52294


    So when user selects a client from the List it will then auto populate the CaseID field by running that VBA code.

    Will that have something to do with my subform not working?

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    I would assume so, as you do not appear to have CaseID actually on the mainform?
    Also give your controls meaningful names. Get in the habit of doing that.

    You need to use that control as the Master link.
    Not sure if the source for that should be caseID, try it anyway.
    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

  8. #8
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    154
    Quote Originally Posted by Welshgasman View Post
    I would assume so, as you do not appear to have CaseID actually on the mainform?
    Sorry, what do you mean by this as I don't quite understand. I do have a CaseID textbox that gets automatically populated by vba code after user has selected a value in the list box

  9. #9
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    154
    Quote Originally Posted by Welshgasman View Post
    Upload a sample db.
    If you need to hide the data use this
    I have attached my db as I am stuck.
    Please let me know if I have not made it clear on what I am trying to achieve.
    Thank you.
    Attached Files Attached Files

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    Use your control name for the CaseID on the mainform as Master Link value.
    I renamed yours to txtCaseID.
    Attached Thumbnails Attached Thumbnails Screenshot 2024-10-11 123447.png   Screenshot 2024-10-11 123553.png  
    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

  11. #11
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    154
    splendid!
    Thank you so much Welshgasman

  12. #12
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    You're welcome.
    Have a read of these links for naming conventions.
    https://www.google.com/search?q=acce...hrome&ie=UTF-8
    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

  13. #13
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    I think your error is the after update event of the listbox.

    Your main form (The parent of the listbox) is bound to tblCases.
    The listbox is also bound to tblCases.

    If you sync them then the Master/Child links will work correctly. By using the textbox, the main form is staying on CaseID 1 while your subform is moving to another CaseID.

    In the after update of your listbox use the findfirst method to sync them.

    Code:
    Private Sub List15_AfterUpdate()
    
        Dim rs As DAO.Recordset
        Set rs = Me.RecordsetClone
    
    
        With rs
            .FindFirst "CaseID = " & Me.List15
    
    
            If Not .NoMatch Then
                Me.Bookmark = rs.Bookmark
            Else
                ' a messagebox if you like
            End If
            
        End With
    
    
    End Sub
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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 Report from filtered datasheet form
    By gemadan96 in forum Reports
    Replies: 7
    Last Post: 01-03-2014, 05:12 PM
  3. Replies: 2
    Last Post: 04-20-2013, 03:37 AM
  4. Replies: 3
    Last Post: 11-06-2012, 03:25 PM
  5. Displaying query results within a form
    By Remster in forum Forms
    Replies: 5
    Last Post: 10-05-2010, 09:56 PM

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