increment variable with loop?

bionicman

Registered User.
Local time
Today, 12:33
Joined
Jul 22, 2003
Messages
145
I have 9 variables that i have declared as follows:

Code:
Dim EmailAddress1, EmailAddress2, EmailAddress3, EmailAddress4, EmailAddress5, EmailAddress6, EmailAddress7, EmailAddress8, EmailAddress9 As String

I then have a process that loops through a string to pull out e-mail addresses that are seperated by a comma. I am trying to assign each e-mail address to the variables that i have declared for later use.

I tried to add the following to my loop, but it didn't work:

Code:
EmailAddress & counternumber = "Email Address Goes Here"

I was hoping the above code would come out like EmailAddress1="Email Address Goes Here"

Is this even possible to do? If not, how can i increment variables along with my loop?

Thank You!
 
Get away from the multiple variables. You really don't need them. You can loop and build your string by using:

Dim strEmail As String

Do Until ...whatever you are doing here
strEmail = strEmail & ";" Me.YourTextBox 'or however you are getting the email address
..do whatever here to move to the next record, or whatever
Loop

Then, use strEmail for sending.
 
that is actually exactly opposite of what i am trying to do. I am having the user type in the addresses in an inputbox seperated by a comma. I am then going through the string to take apart the string and store the individual e-mail addresses in a table (not the table the form is based on).
 
Ah, then don't create more variables, use the Split function

Code:
Dim varEmail As Variant
Dim intCount As Integer

varEmail = Split(Me.YourTextBoxNameHere, ",")

intCount = UBound(varEmail) + 1
Do Until intCount = 0
   Do your stuff to send to table here with varEmail(intCount)
    intCount = intCount - 1
Loop
 
Thanks for the help... i think i am making this more difficult than it needs to be. I was going to store everything in variables and then add to the table at the end of my code, but your code shows adding to the table on the fly which i think will work better.
 

Users who are viewing this thread

Back
Top Bottom