Is it possible to set MSAccess form object properties using variable substitution?

Posted on 2007-08-08
Last Modified: 2008-01-09
I have an MSAccess form that have 10 label and 10 text fields.  All fields are all set to invisible, and disabled, and depending on what selection the user selects, anywhere from 1 - 10 fields will become visible and the label captions will get set.  My question is this...depending on the selection, the label captions will be set to different things.  I want to set them using a loop.  The labels are called lblparm1, lblparm2, lblparm3, lblparm4, etc.   How can I set this using a loop or can I do that at all.  Can I do something like this:
for x = 1 to number of parms in query
strlabel = "lblparm" & cstr(x)
strlable.caption = .........
next i

I tried this but it doesn't work.  Is it possible?
Question by:CaroleTSullivan
    LVL 61

    Accepted Solution

    Try this:

    DIm I as Integer
    For I = 1 to YourNumber
          Me.Controls("lblparm" & I).caption = "Label " & I
    LVL 75

    Expert Comment

    by:DatabaseMX (Joe Anderson - Access MVP)
    I see what you want to do, but what is the field name in the query that contains the label information?

    LVL 26

    Expert Comment

    why not make it as control array?
    LVL 75

    Expert Comment

    by:DatabaseMX (Joe Anderson - Access MVP)
    Carole ... are you wanting to set the label Captions from data in the query?


    Author Comment

    thank you everyone!
    LVL 61

    Expert Comment

    Glad to help.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    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…
    Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
    In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

    731 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

    18 Experts available now in Live!

    Get 1:1 Help Now