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

Referencing Subform Controls from Main Form

Status
Not open for further replies.

SOMSteve

Technical User
May 17, 2007
27
US
I am using ACCESS 2002 SP3 and running into a problem. In the main form the user selects an item type from a drop-down list. If it is equal to Equipment or Vehicle then select fields are supposed to appear in a subform embedded on the main form. The area where I'm having difficulty is trying to reference the subform controls from the main form. I've copied my code below, if anyone has any suggestions on how to make this work I would greatly appreciate any help. Thanks!

Code:
Private Sub cboItemType_AfterUpdate()
'Sends the item type from the main form to the sub-form, this may not be necessary if I can get the control feature to work right.
Me.subfrmSalesInternet.Form.cboItemType = Me!cboItemType
'Tells the subform to look at the "tag" line in each control to search for Equipment and Vehicle and display if they match.
Dim ctl As Control, Detect As String
   Detect = "EquipmentVehicle"
    For Each ctl In Me.subfrmSalesInternet.Form.Controls
      If ctl.Tag <> "" Then
         If InStr(1, Detect, ctl.Tag) > 0 Then
'This next line is where I am having problems
            Me(ctl.Name).Visible = (Nz(Me.cboItemType, "") = ctl.Tag)
         End If
      End If
   Next
End Sub


Thanks again,
Steve
 
Why have you got all this detail?

[tt]Me(ctl.Name).Visible = (Nz(Me.cboItemType, "") = ctl.Tag)[/tt]

You have already tested and found that the control tag is contained in Detect.
 
Perhaps this ?
ctl.Visible = (Nz(Me.cboItemType, "") = ctl.Tag)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for the reply Remou.

The code I'm using is what I was have used on a number other forms successfully (came from a previous post on this forum), but I never tried using it to reference a subform with it. Now I am just trying to adopt it to fit with the subform. I'm fairly new at coding so I may not know the best way of doing these things.

The purpose of:
Me(ctl.Name).Visible = (Nz(Me.cboItemType, "") = ctl.Tag)
Is to make the particular fields on the subform visible only if they match the item type on the main form, otherwise they shouldn't be visible. I put either "Vehicle" or "Equipment" in each of their tag lines depending on which item type the field was associated with.

I don't know if that answers your question, let me know if I can give you any more detail to help clarify. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top