[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 799
  • Last Modified:

Access:Refresh my subforrm: Is not working

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?
  • 2
2 Solutions
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
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.


ouestqueAuthor Commented:
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?
Sry, you needed the form qualifier too.

me.sub_form2.form.RecordSource = "sortbyfirstname"

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now