ASP loop

L

L

Below is the code to send an email message based on user selection. The only
problem is when there are duplicate states, the email message is sent 3 times
instead of 2 times. This is the correct message:
Any ideas?
------------------------
Here is your requested VAR information:

VAR Contact Name: John Peace

Company Name: AccountNet

Address: 1333 Broadway, Suite 632

City: New York

State: New York

Zip Code: 10018

Phone Number: 212-244-9009

Email Address: (e-mail address removed)

Website: http://www.accountnet.com

***************************************

VAR Contact Name: Gwen Blakemore

Company Name: Queue Associates

Address: 42 Broadway, Suite 1814

City: New York

State: New York

Zip Code: 10004

Phone Number: 212-269-1313 x232

Email Address: (e-mail address removed)

Website: http://www.queueassoc.com

***************************************

This message is sent then 1 minute later another message is sent with this
information:
Here is your requested VAR information:

VAR Contact Name: John Peace

Company Name: AccountNet

Address: 1333 Broadway, Suite 632

City: New York

State: New York

Zip Code: 10018

Phone Number: 212-244-9009

Email Address: (e-mail address removed)

Website: http://www.accountnet.com

***************************************
Here is the code:
<% .....
objRS.Open strsql, myconn
'
Do While Not objRS.EOF
'
myname = objRS("ContactName")
mycompany = objRS("CompanyName")
myaddress = objRS("ContactAddress")
mycity = objRS("ContactCity")
mystate = objRS("ContactState")
myzip = objRS("ContactZip")
myphone = objRS("ContactPhone")
myemail = objRS("ContactEmail")
myURL = objRS("ContactURL")
'
strBody = strBody & "VAR Contact Name: " & vbTab & myname & vbTab & vbCrLf
& vbCrLf
strBody = strBody & "Company Name: " &vbTab & mycompany & vbTab & vbCrLf
&vbCrLf
strBody = strBody & "Address: " &vbTab & myaddress & vbTab & vbCrLf & vbCrLf
strBody = strBody & "City: " &vbTab & mycity & vbCrLf & vbCrLf
strBody = strBody & "State: " &vbTab & mystate & vbCrLf & vbCrLf
strBody = strBody & "Zip Code: " &vbTab & myzip & vbCrLf & vbCrLf
strBody = strBody & "Phone Number: " &vbTab & myphone &vbCrLf & vbCrLf
strBody = strBody & "Email Address: " &vbTab & myemail & vbCrLf & vbCrLf
strBody = strBody & "Website: " &vbTab & myurl & vbCrLf & vbCrLf
strBody = strBody & strstars &vbTab & vbCrLf & vbCrLf
'
set myCDONTSMail = CreateObject("CDONTS.NewMail")
myCDONTSMail.Send strFrom, strTo, strSubject, strBody
set myCDONTSMail = Nothing
'
objRS.MoveNext
Loop
'
objRS.close
myconn.Close
set myconn = Nothing

%>
 
K

Kevin Spencer

My guess is that something is causing your query to fetch 3 records (1
duplicate) instead of 2. There is nothing wrong with the code you posted, so
it must be in the code you did NOT post.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
The sun never sets on
the Kingdom of Heaven
 
C

clintonG

<snip />

Use a nested loop...

' initialize counter variable
dim count = 0

'START: outer loop to control number of desired loops
do while count < 3

'START: your stuff
Do While Not objRS.EOF
strBody = strBody & "VAR Contact Name: " & vbTab & myname & vbTab & vbCrLf
& vbCrLf
strBody = strBody & "Company Name: " &vbTab & mycompany & vbTab & vbCrLf
...
...
...
Loop
'END: your stuff

loop
'END: outer loop to control number of desired loops

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
 
S

Stefan B Rusynko

Nothing wrong w/ the code other than it is very server intensive "looping"
- if there are 100 recordsets there are 100 emails (when one will do)

The part that send mail
set myCDONTSMail = CreateObject("CDONTS.NewMail")
myCDONTSMail.Send strFrom, strTo, strSubject, strBody
set myCDONTSMail = Nothing
Should be moved outside of the loop




| My guess is that something is causing your query to fetch 3 records (1
| duplicate) instead of 2. There is nothing wrong with the code you posted, so
| it must be in the code you did NOT post.
|
| --
| HTH,
|
| Kevin Spencer
| Microsoft MVP
| .Net Developer
| The sun never sets on
| the Kingdom of Heaven
|
| | > Below is the code to send an email message based on user selection. The
| > only
| > problem is when there are duplicate states, the email message is sent 3
| > times
| > instead of 2 times. This is the correct message:
| > Any ideas?
| > ------------------------
| > Here is your requested VAR information:
| >
| > VAR Contact Name: John Peace
| >
| > Company Name: AccountNet
| >
| > Address: 1333 Broadway, Suite 632
| >
| > City: New York
| >
| > State: New York
| >
| > Zip Code: 10018
| >
| > Phone Number: 212-244-9009
| >
| > Email Address: (e-mail address removed)
| >
| > Website: http://www.accountnet.com
| >
| > ***************************************
| >
| > VAR Contact Name: Gwen Blakemore
| >
| > Company Name: Queue Associates
| >
| > Address: 42 Broadway, Suite 1814
| >
| > City: New York
| >
| > State: New York
| >
| > Zip Code: 10004
| >
| > Phone Number: 212-269-1313 x232
| >
| > Email Address: (e-mail address removed)
| >
| > Website: http://www.queueassoc.com
| >
| > ***************************************
| >
| > This message is sent then 1 minute later another message is sent with
| > this
| > information:
| > Here is your requested VAR information:
| >
| > VAR Contact Name: John Peace
| >
| > Company Name: AccountNet
| >
| > Address: 1333 Broadway, Suite 632
| >
| > City: New York
| >
| > State: New York
| >
| > Zip Code: 10018
| >
| > Phone Number: 212-244-9009
| >
| > Email Address: (e-mail address removed)
| >
| > Website: http://www.accountnet.com
| >
| > ***************************************
| > Here is the code:
| > <% .....
| > objRS.Open strsql, myconn
| > '
| > Do While Not objRS.EOF
| > '
| > myname = objRS("ContactName")
| > mycompany = objRS("CompanyName")
| > myaddress = objRS("ContactAddress")
| > mycity = objRS("ContactCity")
| > mystate = objRS("ContactState")
| > myzip = objRS("ContactZip")
| > myphone = objRS("ContactPhone")
| > myemail = objRS("ContactEmail")
| > myURL = objRS("ContactURL")
| > '
| > strBody = strBody & "VAR Contact Name: " & vbTab & myname & vbTab & vbCrLf
| > & vbCrLf
| > strBody = strBody & "Company Name: " &vbTab & mycompany & vbTab & vbCrLf
| > &vbCrLf
| > strBody = strBody & "Address: " &vbTab & myaddress & vbTab & vbCrLf &
| > vbCrLf
| > strBody = strBody & "City: " &vbTab & mycity & vbCrLf & vbCrLf
| > strBody = strBody & "State: " &vbTab & mystate & vbCrLf & vbCrLf
| > strBody = strBody & "Zip Code: " &vbTab & myzip & vbCrLf & vbCrLf
| > strBody = strBody & "Phone Number: " &vbTab & myphone &vbCrLf & vbCrLf
| > strBody = strBody & "Email Address: " &vbTab & myemail & vbCrLf & vbCrLf
| > strBody = strBody & "Website: " &vbTab & myurl & vbCrLf & vbCrLf
| > strBody = strBody & strstars &vbTab & vbCrLf & vbCrLf
| > '
| > set myCDONTSMail = CreateObject("CDONTS.NewMail")
| > myCDONTSMail.Send strFrom, strTo, strSubject, strBody
| > set myCDONTSMail = Nothing
| > '
| > objRS.MoveNext
| > Loop
| > '
| > objRS.close
| > myconn.Close
| > set myconn = Nothing
| >
| > %>
| >
|
|
 
K

Kevin Spencer

Yes, well, that doesn't explain why he's sending duplicates. That is what I
was addressing.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
The sun never sets on
the Kingdom of Heaven
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top