Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

objmessage.to from recordset 2

Status
Not open for further replies.
Aug 1, 2003
85
US
I'm using this code to send an email when a ticket is placed, except objMessage.TO was my email address. I can't seem to get a variable to work in that line.

<%
If Request.Form("submit").Count > 0 Then

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "TSR Form"
objMessage.Sender = "Martin_Door_Intranet"
objMessage.To = <%=(Recordset1.Fields.Item(emailaddress).Value)%>
objMessage.TextBody = "This TSR was logged by " & Request.Form("FirstName")& " " & Request.Form("LastName")
objMessage.Configuration.Fields.Item _
(" = 2
objMessage.Configuration.Fields.Item _
(" = "mail"
objMessage.Configuration.Fields.Item _
(" = 25
objMessage.Configuration.Fields.Update
objMessage.Send
Set objMessage = Nothing
End If
%>

I can hardcode the email address' in there and get it to work but I'm trying to get them from a recordset. Oh, there could be multiple addresses.

Any Ideas?
Dan
 
Ok it works now, I had to put the recordset at the top of the page then the objmessage. The insert still works and I just need to test multiple email addresses.

<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_conntesttsrserv_STRING
Recordset1.Source = "SELECT useraccess.emailaddress, pagelinks.pagelinks FROM useraccess INNER JOIN (pagelinks INNER JOIN linkdetail ON pagelinks.pagelinkID = linkdetail.pagelinkIDdetail) ON useraccess.UserID = linkdetail.userID WHERE pagelinks.pagelinks='tsr'"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<%
If Request.Form("submit").Count > 0 Then

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "TSR Form"
objMessage.Sender = "Martin_Door_Intranet"
iCount = 0
sTo = ""
do while not Recordset1.eof
'increment counter
iCount = iCount + 1

'Add separator between addresses
if (iCount > 1) then sTo = sTo & ";"

'Append this address to To string
sTo = sTo & Recordset1("emailaddress")

'Move to next address
Recordset1.movenext
loop

'use semi-colon separated string of addresses
objMessage.to = sTo

objMessage.TextBody = "This TSR was logged by " & Request.Form("FirstName")& " " & Request.Form("LastName")
objMessage.Configuration.Fields.Item _
(" = 2
objMessage.Configuration.Fields.Item _
(" = "mail"
objMessage.Configuration.Fields.Item _
(" = 25
objMessage.Configuration.Fields.Update
objMessage.Send
Set objMessage = Nothing
End If
%>
 
So the script was terminating or redirecting or something .... somewhere in the middle ? Such that it never reached the email logic at the end?
 
That's correct Sheco. It probably has to do with retreiving the autonumber
 
Well... everything works great multiple emails and all.
Thanks for all the help.
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top