Access:Refresh my subforrm: Is not working

Posted on 2007-10-16
Last Modified: 2013-11-28
My database has the following:
2 forms titled form1 and sub_form2
2 queries titled sortbyfirstname, sortbylastname
1 table titled Names

 On form1 there is subform2 two optionboxes(optionbox1 and optionbox2)

 When a user chooses optionbox1 then it runs the following code:
[Forms]![sub_form2].RecordSource = "sortbyfirstname"

When a user chooses optionbox2 then it runs the following code:
[Forms]![sub_form2].RecordSource = "sortbylastname"

When I open both forms, I notice that the above code changes subform2, but form1 there is no change. I have tried docmd.requery sub_form2 but the subform in form 1 does not change. Does anyone know why. Can anyone help me figure out what to do to make the subform refresh when its recordsource is changed?
Question by:ouestque
    LVL 13

    Assisted Solution

    Did you try something like this:

    Dim strSort

    Select Case me.YourComboBox
         Case = "Sort By First Name"
              strSort = "sortbyfirstname"
         Case = "Sort By Last Name"
              strSort = "sortbylastname"
    End Select

    me.sub_form2.recordsource = strSort
    LVL 2

    Expert Comment

    I think you're confusing referencing forms and subforms. When you're wanting to reference the subform you *must* reference it via it's parent.

    If I understand your post correctly, what happens is you open both form 1 with the subform2 on it, and also the subform2-on-it's-own. When you click your button, only the subform2-on-it's-own is getting updated, but it's the subform on form1 you're wanting to update?

    adraughn's correction correctly references the subform2 on the main form1. If you just change your [Forms]![sub_form2].RecordSource = "sortbyfirstname"
    me.sub_form2.RecordSource = "sortbyfirstname"
    ... then you should see the subform updating, but the subform2-opened-on-it's-own no longer refreshing.



    Author Comment

    Here are the details for the subform on form1: Name=sub_form and Source Object=sub_form2

    I have tried swampy's idea above but I get the following error: "Method or data member not found."

    Here is what I am using: me.sub_form2.RecordSource = "sortbyfirstname"

    I thought maybe the error is that I am referring to sub_form2, instead of the name of the subform on form1 so I tried the following and got the same error: me.sub_form.RecordSource = "sortbyfirstname"

    Ya'll have any ideas?
    LVL 2

    Accepted Solution

    Sry, you needed the form qualifier too.

    me.sub_form2.form.RecordSource = "sortbyfirstname"

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
    QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
    Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now