Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Calculating a control name

Posted on 1999-06-28
9
Medium Priority
?
154 Views
Last Modified: 2012-05-04
I want to be able to construct the name of a control based on a calculation. Let's say I have a bunch of text controls, e.g., txtA1, txtA2, . . ., txtA15. Based on a calculation I want to be able to say:

txtA<n>.Text = (expression),

where <n> is any number from 1 to 15.
Right now I do it with a bunch of If and ElseIf statements, but I am looking for a way to construct the left-hand side of the statement above instead.

0
Comment
Question by:cbutton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 1

Expert Comment

by:Neal Hartman
ID: 1520269
Use a control array

txt(1).text
txt(2).text
etc...

0
 
LVL 15

Accepted Solution

by:
ameba earned 400 total points
ID: 1520270
' add textbox, paste this code
Option Explicit

Private Sub Form_Click()
    Dim i As Integer
    i = 1
    Me.Controls("Text" & i).Text = "Hello!"
End Sub

0
 
LVL 15

Expert Comment

by:ameba
ID: 1520271
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 10

Expert Comment

by:caraf_g
ID: 1520272
Dang, ameba, you're too quick :-)

cbutton, ameba has the right solution for you!
0
 
LVL 15

Expert Comment

by:ameba
ID: 1520273
Yes, you are slow :)
0
 

Author Comment

by:cbutton
ID: 1520274
Thanks, ameba. It works just the way you said it would.

By the way, I don't really understand "Me."
0
 
LVL 15

Expert Comment

by:ameba
ID: 1520275
Thanks for your points.

'Me' represents current form instance in the sample.
Another sample:
To close a form, use
   Unload Me
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1520276
"Unload Me"
Yes - but only if you're inside a form's code module. To clarify:

Let's say you have a project with two forms, Form1 and Form2 and an ordinary basic module Module1

Inside the code module for Form1, Unload Me unloads Form1
Inside the code module for Form2, Unload Me unloads Form2
Inside Module1... Module1 is not the code module for a form, so Unload Me is not allowed.

PS - if you're working with multiple instances of a form, Unload Me unloads the current instance. If not, ignore this PS.
0
 
LVL 15

Expert Comment

by:ameba
ID: 1520277
Thanks for clarification.
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

670 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