Syntax to set controlsource of listbox in subform

  • Thread starter Thread starter kc-mass
  • Start date Start date
K

kc-mass

I need to set the control source of a listbox in VBA on a subform.
I have tried several variations in the vein of:
Forms!myParentFrm!MySubFrm!myListBox = "myQuery"
Forms!myParentFrm!MySubFrm.Controls!myListBox = "myQuery"

Search of the web reveals nothing.

Any good ideas?

Thx

Kevin
 
kc-mass said:
I need to set the control source of a listbox in VBA on a subform.
I have tried several variations in the vein of:
Forms!myParentFrm!MySubFrm!myListBox = "myQuery"
Forms!myParentFrm!MySubFrm.Controls!myListBox = "myQuery"


Is it the ControlSource property you want to set, or is it (more likely, it
seems to me) the RowSource property. For the RowSource property, try this:

Forms!myParentFrm!MySubFrm!myListBox.RowSource = "myQuery"

Under some circumstances, it *may* be necessary to add the ".Form"
qualifier:

Forms!myParentFrm!MySubFrm.Form!myListBox.RowSource = "myQuery"

Note that, in both the above cases, "MySubFrm" must be the name of the
subform *control* on the main form, which may or may not be the same as the
name of the form object the subform control is displaying.
 
Thanks to both of you for the assistance, unfortunately the problem
continues.
The literal code is :
Forms!frmTab!frmLoadProviders.Form!lstAllProviders.RecordSource =
"qryGetprovider"

The error reported is:
"Microsoft Access can't find the field 'frmLoadProviders' referred
to in your expression."
I tried the four options provided and get the same error.

thx for any help

Kevin
 
Are you certain that the subform control on frmTab is named
frmLoadProviders? Depending on how you added the form as a subform, the name
of the subform control may be different than the name of the form being used
as a subform.
 
Hi Doug

When I document the form the frmLoadProviders is referred to as:
Subform/Subreport: frmLoadProvider

Any advice would be appreciated.

Kevin
 
Hi Doug
Good catch. It is "frmLoadProviders". I think that comes from doing this
for two hours.
The source is now being correctly applied.

I then need to requery the control, Is the syntax the same?

Thx

Kevin
 
I then need to requery the control, Is the syntax the same?

Yes, instead of .Recordsource use .Requery at the end of the statement...
the expression should otherwise be the same.

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
kc-mass said:
Hi Doug
Good catch. It is "frmLoadProviders". I think that comes from doing this
for two hours.
The source is now being correctly applied.

I then need to requery the control, Is the syntax the same?


If you set a control's RowSource property or a form's RecordSource property,
you don't need to requery the control or form. Changing the property forces
a requery.
 
I want to thank all of you for your help the controls now fill with data.
I had to set the rowsource vise the controlsource.
Great, extremely timely advice.

Thx a million
 
Back
Top