access object in useform by name

Posted on 2006-05-09
Last Modified: 2010-05-01
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?
Question by:vishalarya
    LVL 65

    Accepted Solution

    This works in Access, I believe in VB too...
    Msgbox Me(get_label).Caption   'Where get_label is the name of a control
    LVL 85

    Assisted Solution

    by:Rory Archibald
    Can you show your exact code as that syntax should work with userforms too?


    Author Comment

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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now