Syntax to set controlsource of listbox in subform

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
 
D

Dirk Goldgar

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.
 
K

kc-mass

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
 
D

Douglas J. Steele

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.
 
K

kc-mass

Hi Doug

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

Any advice would be appreciated.

Kevin
 
D

Douglas J. Steele

Which is it: frmLoadProviders (with an s) or frmLoadProvider (without the
s)?
 
K

kc-mass

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
 
J

Jack Leach

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)
 
D

Dirk Goldgar

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.
 
K

kc-mass

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
 
Top