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!

refer to variables in loops

Status
Not open for further replies.

autex

Technical User
Jan 11, 2005
75
0
0
US
I'm trying to be more efficient with my code. I've got 6 variables c1, c2, ...., c6 I want to refer to the value of these variables in a loop. This is my loop:

For s = 1 To 6
c = "c" & s
If c <> "" Then
SendKeys c & "{enter}"
End If
Next s

I'm getting this
c1
c2
c3
c4
c5
c6

I want to get the values of c1, c2 etc.

Any advice?
 
Why not simply using an array ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
autex,

How are the values of the variables stored? If I knew more, I might be able to help.
 
I've never used arrays, I'll check them out thanks.

How are the variables stored?
the variables are values from the forms and subforms


c1 = Nz(me.textbox, "")
c2= nz(me.adifferenttextbox,"")
etc.



Me.Text0.SetFocus

For s = 1 To 6
c = "c" & s
If c <> "" Then
SendKeys c & "{enter}"
End If
Next s


 
I like arrays, thanks for the suggestion. I still need help knowing what I don't know. I'll scratch arrays off the don'tknow list.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top