Assign Variable to Textbox Name and Set Visible Property

Posted on 2006-05-05
Last Modified: 2012-06-21
Can I assign a variable to the name of a textbox and then set the visible property?
My string variable is "strFailCode". I look up the value of Fail Code in a table and then add "txt" to the front of the name.
I then want to turn off the visible property of the textbox in code.
(For example: the first record in the table would be BentPins and the textbox is Named txtBentPins, so my variable would be equal to "txtBentPins")
Using strFailCode.Visible won't work of course, is there a way to let VB6 recognize that strFailCode is the textbox name?
I am new to VB coding.
Question by:maryburgess
    LVL 5

    Accepted Solution

    You can do this by:

    Forms!FormName!(strFailCode).visible = false
    LVL 5

    Expert Comment

    By the way, where i put "FormName" in my last comment, you need to type the actual name of the form.
    LVL 58

    Expert Comment


    jet46 is basically correct, but there is a typo: an additional !
    From the form itself, use:

        Me(strYourVariable).Visible  = True  ' which is a shortcut for
        Me.Controls(strYourVariable).Visible = True


    Author Comment

    The answer from jet46 worked great as written. Thanks to both of you for the response!

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    In the previous article, Using a Critera Form to Filter Records (, the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
    QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
    With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

    755 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

    22 Experts available now in Live!

    Get 1:1 Help Now