how to change sub form record source?

L

lynda

Suppose I have a subFormAAA, and I have three queries:
query1, query2, query3. I have three option buttons:
option1, option2, option3. If option1 is slected, I want
to set the subFormAAA's record source as query1, if
option2 is selected, the subFormAAA's record source will
be query2, if option 3 is selected, the subFormAAA's
record source will be query3. How could I change the sub
form's record source? Thansk for your help!
Best Regards
Lynda
 
S

Sandra Daigle

Hi Lynda,

First, your option buttons should be part of an option group (or frame). The
group itself has a value based on which of the options is selected. Then you
can use a case statement as follows:

select case me.MyOptionGroup
case 1
me.subformAAA.form.recordsource="query1"
case 2
me.subformAAA.form.recordsource="query2"
case 3
me.subformAAA.form.recordsource="query3"
end select

Where 'MyOptionGroup' is the name of the option group control and
'subformAAA' is the name of the subform control on the main form.

Hopefully your queries are actually named something more meaningful than
"query1", "query2" and "query3" but if they were all named with the same
prefix and only the suffix of 1-3 then you could shorten the above by just
doing this:

me.subformAAA.form.recordsource="MyQuery" & me.myOptionGroup
 
L

lynda

Hi, Sandra,
Thank you very much! It works beautifully. I do have
meaningful name for my subform and queries. Have a great
day!
Best Regards
Lynda
-----Original Message-----
Hi Lynda,

First, your option buttons should be part of an option group (or frame). The
group itself has a value based on which of the options is selected. Then you
can use a case statement as follows:

select case me.MyOptionGroup
case 1
me.subformAAA.form.recordsource="query1"
case 2
me.subformAAA.form.recordsource="query2"
case 3
me.subformAAA.form.recordsource="query3"
end select

Where 'MyOptionGroup' is the name of the option group control and
'subformAAA' is the name of the subform control on the main form.

Hopefully your queries are actually named something more meaningful than
"query1", "query2" and "query3" but if they were all named with the same
prefix and only the suffix of 1-3 then you could shorten the above by just
doing this:

me.subformAAA.form.recordsource="MyQuery" & me.myOptionGroup

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Suppose I have a subFormAAA, and I have three queries:
query1, query2, query3. I have three option buttons:
option1, option2, option3. If option1 is slected, I want
to set the subFormAAA's record source as query1, if
option2 is selected, the subFormAAA's record source will
be query2, if option 3 is selected, the subFormAAA's
record source will be query3. How could I change the sub
form's record source? Thansk for your help!
Best Regards
Lynda

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top