|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
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
|
|||
|
|||
|
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
%>
|
|
#2
|
||||
|
||||
|
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
|
|
#3
|
|||
|
|||
|
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? |
|
#4
|
||||
|
||||
|
Quote:
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? |
|
#5
|
|||
|
|||
|
Quote:
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... |
|
#6
|
||||
|
||||
|
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:
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()
%>
Last edited by keep_it_simple : May 13th, 2008 at 03:21 AM. |
|
#7
|
||||
|
||||
|
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
%>
|
|
#8
|
|||
|
|||
|
Thanks
THANKS for helping me solve this little headache guys...I have definitely learned from this experience.
![]() |
![]() |
| Viewing: ASP Free Forums > Programming > ASP Development > Database - Recordset - HELP with code & Loop |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|