Connecting Tech Pros Worldwide Forums | Help | Site Map

Passing parameter to rowsource of combo box dynamically

Newbie
 
Join Date: Jan 2009
Posts: 3
#1: Jan 6 '09
Hi
I have a main form which contains questions and a subform within it which contains elements which relate to the main form. they are linked by a field called question_ref so if I page through the records on the main form the elements that are relevant to that question display in the subform.

Within the subform I have a combo box which calls a table which contains the following question_ref and a text field. I would like to be able to make the combo box only display data in the combo box that relates to the current question in the subform.

I have tried setting the rowsource of the combo box as following but is does not display any values.(error enter parameter me.question_ref)
Expand|Select|Wrap|Line Numbers
  1. select tbllookup_comment.question_ref,
  2.        tbllookup_comment.text
  3. from tbllookup_comment
  4. where tbllookup_comment.question_ref = me.question_ref (this is a field in my subform)
Any ideas why it is not picking up the data from the me.question_ref field and passing across to the rowsource.

Any help greatly appreciated

NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#2: Jan 6 '09

re: Passing parameter to rowsource of combo box dynamically


Me. is an object reference that works within VBA. It is entirely unknown to (unrecognised by) the SQL interpreter.

It should recognise a fully qualified reference though. The form must be open of course (You may find Referring to Items on a Sub-Form useful).
Newbie
 
Join Date: Jan 2009
Posts: 3
#3: Jan 6 '09

re: Passing parameter to rowsource of combo box dynamically


Hi Thanks for that
I can now get the combo box to display the options for question1 correctly but when I go to the next record in the subform it shows me options in the combo box for the previous record so its not refreshing the combo box as it goes through the records in the sub form, it there someother code I need to do this
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#4: Jan 6 '09

re: Passing parameter to rowsource of combo box dynamically


The SQL doesn't keep repeating its execution.

If the criteria change somehow, and you want to reprocess the query, you need to call a .Requery on the object (You only refer to it as a ComboBox on your SubForm) that the SQL is in.

Does that make sense?
Newbie
 
Join Date: Jan 2009
Posts: 3
#5: Jan 6 '09

re: Passing parameter to rowsource of combo box dynamically


Great thanks for your help thats owkred
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#6: Jan 6 '09

re: Passing parameter to rowsource of combo box dynamically


Great :)

I'm always pleased when something owkrs (LOL).

J/K We all live on typos here ;)
Reply