Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing the Control Source of a subform

Status
Not open for further replies.

marcfl

Technical User
Jan 16, 2008
56
GB
Hi,

I'm trying to change the control source of a subform by the selection of an option in a combobox. Ive created the qrys that i want to be my control source but I have no idea how to write the code for what i want.. :( Help!

Cheers,

marcfl.
 
When changing the properties of a subform there are two property boxes. One of them is on the square at the top left of the form. The other is on the outer edge of the form. The source object properties (Outer edge) allows you to select the form for your sub form. The one box at the top left allows you to change your control source... using the drop down box select your query and that should work.

Good luck.

 
ok maybe i didnt explain it properly.. I have a subform on which there is a combobox. In this combo box there are 12 options, each option has its own query. What i want is for each option to load the query that is related to that option (so there are 12 queries aswell). Im not sure how to do it tho thats the prob.

Cheers,

marcfl.
 
if Forms!mainform!subform.form!comboboxnamename = "Comboboxoption" then me.mainform.recordsource = "queryname"

Maybe something like this?

 
Are you being sarcastic? :) You can put that code into a button or something after you select the combo box option.
 
no lol i wasnt being sarcastic im not like that, it's just that ive been trying to do this for nearly 2 weeks hehe.
 
ok so far i have:

Private Sub Pricelist_AfterUpdate()

If Forms!mainform!SubForm.Form!Pricelist = "Air-Edel" Then Me.mainform.RecordSource = "PricelistAir"

End Sub

and it doesnt work i get:

Compile error:

Method or data member not found

The .mainform is highlighted when i click on ok
 
I may not be interpreting this correctly because the suggestion do no make sense to me. This is what I interpret.

1) You have a subform with a combobox
2) The combo box list Names associated with queries
3) When you select a choice from the combo it should change the recordsource of the subform
4) The mainform recordsource is not an issue

I would have 2 columns in my combobox. The first column is the query name the second is the label. For example.
PriceListAir Air-Edel
The combo properties are something like
bound column: 1
column count: 2
column widths: 0";1"
The value of the combobox is the queryname, however, only the label is shown since the first column is 0 width.

your code becomes in the subform
Code:
Private Sub cmboChoose_AfterUpdate()
  Me.RecordSource = Me.cmboChoose.Value
End Sub
 
Thanks MajP ill give it a whirl today and hopefully itll work! This issue is really getting on my nerves now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top