ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old May 13th, 2008, 01:37 AM
jagreen78 jagreen78 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 9 jagreen78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 17 m 31 sec
Reputation Power: 0
Database - Recordset - HELP with code & Loop

I'm getting this error from the code below:

ADODB.Field error '800a0bcd'

Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

/askThanks.asp, line 326

I think I have a line of code in the wrong place that is looping through my database and sending an email for each email in the table. HELP ME PLEASE...I know my SQL statement works and I have tested it, so I can get the data from the SQL statement but when I perform the loop it only sends ONE email instead of FOUR.

Code:
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
contractorRS_numRows = contractorRS_numRows + Repeat1__numRows

Dim MyVar

While ((Repeat1__numRows <> 0) AND (NOT contractorRS.EOF)) 
	MyVar = (contractorRS.Fields.Item("CEmail").Value)
    Repeat1__index=Repeat1__index+1
    Repeat1__numRows=Repeat1__numRows-1
	contractorRS.MoveNext()

' declare variables
Dim EmailTo
Dim EmailFrom
Dim Subject
Dim askName
Dim askEmail
Dim askPhone
Dim askQuestion



' get posted data into variables
EmailTo = MyVar
EmailFrom = "questions@site.com"
Subject = "Customer Question from The Contractors Registry"
askName = Request.form("askName")
askEmail = Request.form("askEmail")
askPhone = Request.form("askPhone")
askQuestion = Request.form("askQuestion")



' prepare email body text
Dim Body
Body = Body & "A customer has sent YOU a question from The Site" & VbCrLf
Body = Body & "Their name is: " & askName & VbCrLf
Body = Body & "Their contact number is: " & askPhone & VbCrLf
Body = Body & "Their return email is: " & askEmail & VbCrLf & VbCrLf
Body = Body & "Their question is: " & askQuestion & VbCrLf


     dim cdoMessage, cdoConfig


       set cdoMessage = Server.CreateObject("CDO.Message")
       set cdoConfig = Server.CreateObject("CDO.Configuration")

       cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
       cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
      'cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
	   cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "c:\inetpub\mailroot\pickup"    


       cdoConfig.Fields.Update


       set cdoMessage.Configuration = cdoConfig

       cdoMessage.From =  EmailFrom
       cdoMessage.To = EmailTo
       cdoMessage.Subject = Subject
       cdoMessage.TextBody = Body

       cdoMessage.Send


       set cdoMessage = Nothing
       set cdoConfig = Nothing
	   
Wend
%>

Reply With Quote
  #2  
Old May 13th, 2008, 02:06 AM
keep_it_simple's Avatar
keep_it_simple keep_it_simple is offline
KIS
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jul 2007
Location: USA
Posts: 1,031 keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 8 h 12 m 51 sec
Reputation Power: 340
Send a message via Yahoo to keep_it_simple
start organizing your code better and you'll be able to debug much faster....see in red

Code:
<%
Dim Repeat1__numRows
Dim EmailTo
Dim EmailFrom
Dim Subject
Dim askName
Dim askEmail
Dim askPhone
Dim askQuestion
Dim Repeat1__index
Dim MyVar
Dim Body
Dim cdoMessage, cdoConfig


EmailFrom = "questions@site.com"
Subject = "Customer Question from The Contractors Registry"
askName = Request.form("askName")
askEmail = Request.form("askEmail")
askPhone = Request.form("askPhone")
askQuestion = Request.form("askQuestion")



Body = Body & "A customer has sent YOU a question from The Site" & VbCrLf
Body = Body & "Their name is: " & askName & VbCrLf
Body = Body & "Their contact number is: " & askPhone & VbCrLf
Body = Body & "Their return email is: " & askEmail & VbCrLf & VbCrLf
Body = Body & "Their question is: " & askQuestion & VbCrLf


Repeat1__numRows = -1
Repeat1__index = 0
contractorRS_numRows = contractorRS_numRows + Repeat1__numRows



While ((Repeat1__numRows <> 0) AND (NOT contractorRS.EOF)) 
	MyVar = (contractorRS.Fields.Item("CEmail").Value)
    Repeat1__index=Repeat1__index+1
    Repeat1__numRows=Repeat1__numRows-1



  ' email code




   contractorRS.MoveNext()

%>
__________________
Please give respect to those that helped solve an issue by clicking on the reputation icon

Reply With Quote
  #3  
Old May 13th, 2008, 02:21 AM
jagreen78 jagreen78 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 9 jagreen78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 17 m 31 sec
Reputation Power: 0
Why would this

Code:
EmailFrom = "questions@site.com"
Subject = "Customer Question from The Contractors Registry"
askName = Request.form("askName")
askEmail = Request.form("askEmail")
askPhone = Request.form("askPhone")
askQuestion = Request.form("askQuestion")



Body = Body & "A customer has sent YOU a question from The Site" & VbCrLf
Body = Body & "Their name is: " & askName & VbCrLf
Body = Body & "Their contact number is: " & askPhone & VbCrLf
Body = Body & "Their return email is: " & askEmail & VbCrLf & VbCrLf
Body = Body & "Their question is: " & askQuestion & VbCrLf


Be above the loop if I want this message sent to each email?

Reply With Quote
  #4  
Old May 13th, 2008, 02:24 AM
keep_it_simple's Avatar
keep_it_simple keep_it_simple is offline
KIS
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jul 2007
Location: USA
Posts: 1,031 keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 8 h 12 m 51 sec
Reputation Power: 340
Send a message via Yahoo to keep_it_simple
Quote:
Originally Posted by jagreen78
Why would this

Code:
EmailFrom = "questions@site.com"
Subject = "Customer Question from The Contractors Registry"
askName = Request.form("askName")
askEmail = Request.form("askEmail")
askPhone = Request.form("askPhone")
askQuestion = Request.form("askQuestion")



Body = Body & "A customer has sent YOU a question from The Site" & VbCrLf
Body = Body & "Their name is: " & askName & VbCrLf
Body = Body & "Their contact number is: " & askPhone & VbCrLf
Body = Body & "Their return email is: " & askEmail & VbCrLf & VbCrLf
Body = Body & "Their question is: " & askQuestion & VbCrLf


Be above the loop if I want this message sent to each email?



because that's the point of variables...it allows you to assign a value to be used elsewhere on the page....you put the variables in the email code


also....why are you expecting 4 emails?...the form is submitted by one user...yes?

Reply With Quote
  #5  
Old May 13th, 2008, 02:29 AM
jagreen78 jagreen78 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 9 jagreen78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 17 m 31 sec
Reputation Power: 0
Quote:
Originally Posted by keep_it_simple
because that's the point of variables...it allows you to assign a value to be used elsewhere on the page....you put the variables in the email code


also....why are you expecting 4 emails?...the form is submitted by one user...yes?


No.....The whole purpose of the "loop" is to go through my database and get multiple email addresses based on my SQL statement. THEN it will send this same email to every email address that it pulls from the database...

Reply With Quote
  #6  
Old May 13th, 2008, 02:43 AM
keep_it_simple's Avatar
keep_it_simple keep_it_simple is offline
KIS
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jul 2007
Location: USA
Posts: 1,031 keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level)keep_it_simple User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 8 h 12 m 51 sec
Reputation Power: 340
Send a message via Yahoo to keep_it_simple
depending on how your sql statement is set up to grab the emails...you may not need a loop...i went ahead and set up for the loop

Quote:
Originally Posted by jagreen78
No.....The whole purpose of the "loop" is to go through my database and get multiple email addresses based on my SQL statement. THEN it will send this same email to every email address that it pulls from the database...



that's what it does...i'm unfamiliar with the send mail code you have...but...perhaps seeing it helps

click me

Code:
<%
Dim Repeat1__numRows
Dim EmailTo
Dim EmailFrom
Dim Subject
Dim askName
Dim askEmail
Dim askPhone
Dim askQuestion
Dim Repeat1__index
Dim MyVar
Dim Body
Dim cdoMessage, cdoConfig


EmailFrom = "questions@site.com"
Subject = "Customer Question from The Contractors Registry"
askName = Request.form("askName")
askEmail = Request.form("askEmail")
askPhone = Request.form("askPhone")
askQuestion  = Request.form("askQuestion")



Body = Body & "A customer has sent YOU a question from The Site" & VbCrLf
Body = Body & "Their name is: " & askName & VbCrLf
Body = Body & "Their contact number is: " & askPhone & VbCrLf
Body = Body & "Their return email is: " & askEmail & VbCrLf & VbCrLf
Body = Body  & "Their question is: " & askQuestion & VbCrLf


Repeat1__numRows = -1
Repeat1__index = 0
contractorRS_numRows = contractorRS_numRows + Repeat1__numRows



While ((Repeat1__numRows <> 0) AND (NOT contractorRS.EOF)) 
	EmailTo = (contractorRS.Fields.Item("CEmail").Value)
    Repeat1__index=Repeat1__index+1
    Repeat1__numRows=Repeat1__numRows-1



  
       set cdoMessage = Server.CreateObject("CDO.Message")
       set cdoConfig = Server.CreateObject("CDO.Configuration")

       cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
       cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
      'cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
	   cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "c:\inetpub\mailroot\pickup"    


       cdoConfig.Fields.Update


       set cdoMessage.Configuration = cdoConfig

       cdoMessage.From =  EmailFrom
       cdoMessage.To = EmailTo
       cdoMessage.Subject = Subject
       cdoMessage.TextBody = Body

       cdoMessage.Send


       set cdoMessage = Nothing
       set cdoConfig = Nothing
	   




   contractorRS.MoveNext()

%>
Comments on this post
sync_or_swim agrees!
jagreen78 agrees!

Last edited by keep_it_simple : May 13th, 2008 at 03:21 AM.

Reply With Quote
  #7  
Old May 13th, 2008, 04:52 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Contributing User
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,259 sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level)sync_or_swim User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 3 Weeks 2 Days 23 h 8 m 7 sec
Reputation Power: 769
I agree with KIS, it appears that the majority of your variables are static, the only variable that changes at each loop iteration is the mail to address, therefore, you can instantiate your variables outside of your loop.

The only change that I woul dmake to the code would be a check to make sure that the email address is legal before you send the message. at the very least, the email address cannot be empty, and it must contain an @:
Code:
<%
' declare variables
Dim EmailTo, EmailFrom, Subject, askName, askEmail, askPhone, askQuestion, Body, cdoMessage, cdoConfig

' get posted data into variables
EmailFrom = "questions@site.com"
Subject = "Customer Question from The Contractors Registry"
askName = Request.form("askName")
askEmail = Request.form("askEmail")
askPhone = Request.form("askPhone")
askQuestion = Request.form("askQuestion")

' prepare email body text
Dim Body
Body = Body & "A customer has sent YOU a question from The Site" & VbCrLf
Body = Body & "Their name is: " & askName & VbCrLf
Body = Body & "Their contact number is: " & askPhone & VbCrLf
Body = Body & "Their return email is: " & askEmail & VbCrLf & VbCrLf
Body = Body & "Their question is: " & askQuestion & VbCrLf

While NOT contractorRS.EOF
	EmailTo = contractorRS.Fields("CEmail")
    	If Len(EmailTo) > 0 AND InStr(EmailTo, "@") Then
	        set cdoMessage = Server.CreateObject("CDO.Message")
                     set cdoConfig = Server.CreateObject("CDO.Configuration")
	        cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
	        cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
	        cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "c:\inetpub\mailroot\pickup"    
	        cdoConfig.Fields.Update
       	        set cdoMessage.Configuration = cdoConfig
	        cdoMessage.From =  EmailFrom
       	        cdoMessage.To = EmailTo
                     cdoMessage.Subject = Subject
       	        cdoMessage.TextBody = Body
  	        cdoMessage.Send

	        set cdoMessage = Nothing
       	        set cdoConfig = Nothing
	End If
	contractorRS.MoveNext
Wend
%>
Comments on this post
keep_it_simple agrees: well done...extra effort in validity checkng
jagreen78 agrees!

Reply With Quote
  #8  
Old May 13th, 2008, 11:18 AM
jagreen78 jagreen78 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 9 jagreen78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 17 m 31 sec
Reputation Power: 0
Thanks

THANKS for helping me solve this little headache guys...I have definitely learned from this experience.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingASP Development > Database - Recordset - HELP with code & Loop


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway