Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resolve variable name when dim (ing) a variable 1

Status
Not open for further replies.

tabbytab

Technical User
Mar 21, 2005
74
0
0
GB
Hi Guys,

I am trying to achive the following

For x = 1 to 36
Dim ctrl_x

Next

SO I Dim ctrl_1,ctrl_2 where x is resolved to its number

Any ideas
Thanks in advance
TabbyTab:)
 

Dim ctrl(1 To 36) As ...... 'Do not leave it to be of a Variant type

Take a look also to UBoound() & LBound() functions and of course read up on arrays!
 
Tabby, It's been ages since I used array variables but I think you should be looking at something along the lines of:

dim ctrl(36)

Then you call the individual variables with ctrl(1), ctrl(2) etc.
 
Thanks guys .. my mind (what little there is left!) has gone blank - not that I'm very familiar with techi stuff in the first place.

So I have

Dim ctrl(36) As control

For x = 1 to 36
ctrl(x)=Test&x
Next

So I want to fill array with

Pos 1=Test1
Pos 2=Test2
Etc

How can I do that

Many,many thanks in advance
TabbyTab:)
 
What is your "big picture". What are Test and Pos? Are they names of controls, strings, or memory variables?

How about providing some context for your questions?

Duane MS Access MVP
 
Ok .

I am trying to step through a sequence of text boxes on a report to allow me to format / enter data into them.

There is other data of the report that is bound to a query.

So text boxes are named L for level S for score
So 1st row is L1S1, L1S2, L1S3 ..L1S6 and next row is L2S1, L2S2,L2S3 ..etc

I want to be able to use the following extract of code below to format them
For LCounter = 1 to 6
For SCounter = 1 to 6

Dim MyControl As Control

Set MyControl = L&LCounter&S&Scounter (!!!!this does not work
With MyControl
.Top = some number
.Left = some number

Etc
Etc
End With
Next
Next

One of my problems is that I need to have a unique control name

Any help would me appreciated

Ragards
TabbyTab :)
 
Couldn't you use something like:

Code:
Private Sub Example()
    Dim MyCtrl As Access.Control
    
    For Each MyCtrl In Me.Controls
        If MyCtrl.Name = "SomeTextbox" Then
            'Format accordingly
        ElseIf MyCtrl.Name Then
            'Do something else
        End If
    Next MyCtrl
End Sub

or maybe:

Code:
Private Sub Example()
    Dim MyCtrl As Access.Control
    
    For lcounter = 1 To 6
        For sCounter = 1 To 6
            Set MyCtrl = Me.Controls("L" & lcounter & "S" & sCounter)
            
            myctrl.left=A number
            myctrl.Top=A number
            Next lcounter
        Next sCounter
End Sub

Ed Metcalfe.

Please do not feed the trolls.....
 
Thanks Ed

It works a treat

Another learn't tool in my toolbox

Regards
TabbyTab:)
 
You're welcome. Thanks for the star. :)

Ed Metcalfe.

Please do not feed the trolls.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top