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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referring to Controls on Subforms

Status
Not open for further replies.

Jables

Programmer
Aug 28, 2001
148
US
Here's how my forms are set up.

Main Form ---> frmStreets
SubForm -----> frmPhasingAndCoordination

On the subform, I have two combo boxes. The second combo box gets it's values from a query based on what the user selects in the first combo box. This all works fine if the subform is opened by itself. Here are the names of the combo box controls:

cboMasterLocationPrim
cboMasterLocationSec

Me.cboMasterLocationSec.Rowsource = SELECT [Streets].[SecondaryStreet] FROM Streets WHERE ((([Streets]![PrimaryStreet]=[Forms]![frmStreets]!cboMasterLocationPrim]));

When the user updates the first combo box (cboMasterLocationPrim), there is some VBA code--->Me.cboMasterLocationSec.Requery

This all works fine when the subform is opened by itelf.

When the subform is placed on the main form, It doesn't work. Well, it sort of works. Whenever the user updates the first combo box, the query dialog box pops up and the user must manually enter the search criteria. After this, the second combo box displays the correct values.

Whenever I insert the subform onto the main form, I change the SQL statement to refer to [Forms]![frmStreets]![subfrmPhasingAndCoordination]![cboMasterLocationPrim], but this doesn't do any good.

How should I refer to this control?
 
So do I have to change every bit of code associated with subfrmPhasingAndCoordination? That is, everytime I set a controls property, it has to be referred to as

Forms("frmStreets")("subfrmPhasingAndCoordination").Form.Controls.("cboMasterLocationPrim")

Is there an easier way?

 
Well.....Yes.

To minimize typing, you could:

Dim ctl as control
Set ctl = Forms("frmStreets")("subfrmPhasingAndCoordination").Form.Controls.("cboMasterLocationPrim")

With ctl
.value = "Your VAlue"
.Width = 40
'etc
End With
Or ctl.value =
Or myTextBox = ctl.value

Etc

Tyrone Lumley
augerinn@gte.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top