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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alter variable name in loop

Status
Not open for further replies.

dodgyone

Technical User
Jan 26, 2001
431
GB
I have a Do While -> Loop in my code. I am using the loop counter to adjust objects inside the loop.

So in a simplified way:

Do While intCounter <= 4
'example 1
.Fields("PostCode") = Trim(rs1.Fields("ADDRESS" & intCounter))
'example 2
strOnHold & intCounter = Trim(rs1.Fields("ADDRESS" & intCounter))
Loop

The problem is with example 2. How do I use the intCounter to append the number to the end of the variable?
 
Rather than using the name of the field you could use the index e.g.
Code:
Do While intCounter <= 4
'example 1
.Fields("PostCode") = Trim(rs1.Fields(intCounter))
'example 2
strOnHold & intCounter = Trim(rs1.Fields(intCounter))
Loop
You will just have to check you are pulling the data from the correct fields.

Hope this helps

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Are strOnHold1, strOnHold2, ... controls in the form ?
Me(strOnHold & intCounter) = Trim(rs1.Fields(intCounter))

If they are variables then use an array instead:
strOnHold(intCounter) = Trim(rs1.Fields(intCounter))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top