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!

Using variable to refer to control on subform

Status
Not open for further replies.

genxiii

Technical User
Jun 13, 2003
17
US
Hey guys, i was wondering if this was possible or not. I have a form call SearchCopy and a subform called SearchResultCopy, the subform is in datasheet view. On my form there is a listbox of all the controls on the subform. All the columns on the subform are hidden. When they are selected from the listbox they are unhidden.

what i'm doing now is storing the value from the listbox in a string but can't refer to that control on the subform using the string. Here's the code i'm using.

'shows fieleds that are selected from the list
Dim strFieldName As String
For itemObject = 1 To LUShowField.ListCount - 1
strFieldName = LUShowField.ItemData(itemObject)

If LUShowField.Selected(itemObject) = True Then

Forms!SearchCopy!SearchResult!strFieldName.ColumnHidden = -1

Else

Forms!SearchCopy!SearchResult!strFieldName.ColumnHidden = 0
End If

Next


from this code its looking for the field strFieldName that doesn't exist. instead that variable contains the name of the field but it apparently can't recognize that. is there any other way i can refer to that control on the subform?
i mean i can go in and type that line for every control but there are quite a bit of them which makes the code very messy looking and long. thanks
 
Hi genxiii,

Try:

Forms!SearchCopy!SearchResultCopy.Form.Controls(strFieldName).ColumnHidden = -1

I was a bit confused with the sub form name. In your explanation you've called it "SearchResultCopy" but in your code you have referred to it as "SearchResult".

Anyway, Controls(strFieldName) should do the trick.

Bill
 
worked like a charm, thanks a lot bill. yeah n sorry bout the misunderstanding. i made a copy of the form bfor i started messin with the code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top