For frmCount = 0 To 5
If frmEmail(frmCount) <> "" Then
sSQL2 = "INSERT into Recipient(Email, SenderID)VALUES('" & frmEmail(frmCount) & "'," & Recordset.fields("AID") & ")"
Dconn.Execute sSQL2
End If
Next
Wait i am sorry. are you inserting if you are at the EOF. Is that what you are doing. Just explain a little bit. Let me see if have this right.
You are grabbin five email address from a form. Then you are inserting them to a DB, but you get 2 emails inserted per one form email. which gives you a total of 10. Is that correct. I should of looked at code better.
When I check the DB the emails in the recipients' table is always entered twice for each sender.
Any idea why?
someone said that I may need 2 Dconn objects?
Code:
'--Enter emails in DB
Dim Dconn, sSQL, sSQL2, cmDC, SQL, Recordset
Set Dconn = Server.CreateObject("ADODB.Connection")
Dconn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & _
databasepath & ";"
Set cmdDC = Server.CreateObject("ADODB.Command")
cmdDC.ActiveConnection = Dconn
SQL = "Select Sender.Email, Sender.AID FROM Sender WHERE " & "Sender.Email ='" & SenderEmail & "'"
cmdDC.CommandText = SQL
Set RecordSet = Server.CreateObject("ADODB.Recordset")
RecordSet.Open cmdDC, , 3, 3
If Recordset.EOF Then
sSQL = "INSERT into Sender(Email, OK2Remind, Origin)VALUES('" & SenderEmail & "','" & chkOK & "','" & strOrigin & "')"
Dconn.Execute sSQL
End If
'--use a For Next loop to enter in the 6 emails from the form and the SenderAID field into the Recipient SenderID field.
For frmCount = 0 To 5
If frmEmail(frmCount) <> "" Then
sSQL2 = "INSERT into Recipient(Email, SenderID)VALUES('" & frmEmail(frmCount) & "'," & Recordset.fields("AID") & ")"
Dconn.Execute sSQL2
End If
Next
Dconn.Close
Set Dconn = Nothing
Response.Redirect "Form.asp"
I attached a little project see if it this is what you need.
make sure that you add the email address in the Sender table put [email protected] that is the default for the textbox.
if the db is empty then it writes it one time. If I write one recipient I get only one. If I do more than one they get duplicated!
Very confusing. here's my code: I also changed the frmcount variable to frmcount2 thinking because I used it earlier in code it was messing things up.
Full version of the code!
Have fun.
Code:
<!-- #INCLUDE FILE="validate.asp" -->
<!-- #INCLUDE FILE="data.asp" -->
<%
on error resume next
Dim strAns
strAns = "Please enter a valid e-mail"
If Request.Form("Y1") = "" Then
Session("Y1") = strAns
Response.Redirect "EmailFriend.asp"
End If
Dim MyEmail(5)
Dim frmEmail(5)
Dim SenderEmail
Dim chkOK
Dim Count, frmCount, frmCount2
Dim AllOK, objCDO, objCDO2, txtSubject, txtSubject2
SenderEmail = Request.form("Y1")
MyEmail(0) = Request.form("A1")
MyEmail(1) = Request.form("A2")
MyEmail(2) = Request.form("A3")
MyEmail(3) = Request.form("A4")
MyEmail(4) = Request.form("A5")
MyEmail(5) = Request.form("A6")
chkOK = Request.form("C1")
strOrigin = Request.ServerVariables("HTTP_REFERER")
For Count = 0 to 5
If chkEmail(MyEmail(Count)) = 1 Then
AllOK = AllOK + 1
End If
Next
If chkEmail(SenderEmail) = 1 Then
AllOK = 1
End If
If AllOk = 1 Then
Response.Redirect "error.asp"
End If
If chkOK <> "" Then
chkOK = True
Else
chkOK = False
End If
'--get email addresses
SenderEmail = Request.form("Y1")
frmEmail(0) = Request.form("A1")
frmEmail(1) = Request.form("A2")
frmEmail(2) = Request.form("A3")
frmEmail(3) = Request.form("A4")
frmEmail(4) = Request.form("A5")
frmEmail(5) = Request.form("A6")
'--sends email to Client, cc to host
For frmCount = 0 To 5
If frmEmail(frmCount) <> "" AND AllOk = 0 Then
Set objCDO = Server.CreateObject("CDO.Message")
objCDO.From = "[email protected]"
objCDO.To = frmEmail(frmCount)
objCDO.bcc = "[email protected]"
txtSubject = "recipient test"
objCDO.Subject = "Testing"
objCDO.TextBody = txtSubject
objCDO.Send
Set objCDO = nothing
'--sends confirmation email to sender
Set objCDO2 = Server.CreateObject("CDO.Message")
objCDO2.From = "[email protected]"
objCDO2.To = SenderEmail
objCDO2.bcc = "[email protected]"
txtSubject = "sender test"
objCDO2.Subject = "Testing"
objCDO2.TextBody = txtSubject
objCDO2.Send
Set objCDO2 = nothing
End If
Next
'--Enter emails in DB
Dim Dconn, sSQL, sSQL2, cmDC, SQL, Recordset
Set Dconn = Server.CreateObject("ADODB.Connection")
Dconn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & _
databasepath & ";"
Set cmdDC = Server.CreateObject("ADODB.Command")
cmdDC.ActiveConnection = Dconn
SQL = "Select Sender.Email, Sender.AID FROM Sender WHERE " & "Sender.Email ='" & SenderEmail & "'"
cmdDC.CommandText = SQL
Set RecordSet = Server.CreateObject("ADODB.Recordset")
RecordSet.Open cmdDC, , 3, 3
If Recordset.EOF Then
sSQL = "INSERT into Sender(Email, OK2Remind, Origin)VALUES('" & SenderEmail & "','" & chkOK & "','" & strOrigin & "')"
Dconn.Execute sSQL
End If
'--use a For Next loop to enter in the 6 emails from the form and the SenderAID field into the Recipient SenderID field.
For frmCount2 = 0 To 5
If frmEmail(frmCount2) <> "" Then
sSQL2 = "INSERT into Recipient(Email, SenderID)VALUES('" & frmEmail(frmCount2) & "'," & Recordset.fields("AID") & ")"
Dconn.Execute sSQL2
End If
Next
set cmdDC = nothing
Recordset.close
set recordset = nothing
Dconn.Close
Set Dconn = Nothing
Response.Redirect "Form.asp"
%>
another thing I went ahead and removed the code that sends the emails and I didn't get a duplicate. THere's a clue to this mystery.