• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

access object in useform by name

I have several labels on a userform.  I want to prompt the user to enter the name of the label he wishes ot select, and then have a msgbox pop up with the caption of the label.  For ex:

In the userform:

Name: label1
caption: "hello"

Name: label2
caption: "world"

Name: label3
caption: "today"

if the user enters in "label1", I would like to msgbox "hello".

I tried accessing the item as follows:

string get_label ' gets the value user enters

msgbox me.controls.item(get_label).caption

However, I get a "type mis-match" error.

Any thoughts?
2 Solutions
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
This works in Access, I believe in VB too...
Msgbox Me(get_label).Caption   'Where get_label is the name of a control
Rory ArchibaldCommented:
Can you show your exact code as that syntax should work with userforms too?

vishalaryaAuthor Commented:
oops nevermind my string var was:

get_label = Label & x

but should be:

get_label = "Label" & x

and then me.controls.item(get_label).caption

that works...


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now