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?
ouestqueAsked:
Who is Participating?
 
9swampyCommented:
Sry, you needed the form qualifier too.

me.sub_form2.form.RecordSource = "sortbyfirstname"
0
 
adraughnCommented:
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
me.sub_form2.requery
0
 
9swampyCommented:
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"
...to...
me.sub_form2.RecordSource = "sortbyfirstname"
... then you should see the subform updating, but the subform2-opened-on-it's-own no longer refreshing.

HTH,

Justin
0
 
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?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.