• 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?
Vishalarya
0
vishalarya
Asked:
vishalarya
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
0
 
Rory ArchibaldCommented:
Can you show your exact code as that syntax should work with userforms too?

Rory
0
 
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...

thx
vishalarya
0

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