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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

response.write in a objMessage.TextBody? 1

Status
Not open for further replies.
Aug 1, 2003
85
US
I'm trying to format a textbody to include an approved with the time or just a not approved. I made an if then statement that uses a field from the recordset (approval) and sets it to the variable (variapproval), then I have a hidden field that's named testapproval and that value is the response.write from variapproval. The approval field is a radio button with two values (y,n). If y is checked and the form is submitted the email says approved (+ the time) if n is checked then submitted the email still says approved unless you submit a second time then it says not approved. I tried to do a response.write(variapproval) in the textbody but couldn't get it to work.
So do I try to get the response.write working or figure out how to get the hidden field to refresh correctly?

Here is the code (stripped down to make it easier to read)

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

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "CERF is complete"
objMessage.Sender = "Martin_Door_Intranet"
objMessage.to = "danblack@test.com"
objMessage.TextBody = vbCrLf & Request.Form("testapproval") or Response.write(variapproval)
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
%>



<table>
<%
Dim variapproval
variapproval = ", has Not been Approved at this time." & vbCrLf
If (Recordset1.Fields.Item("approval").Value = "y") Then
variapproval = ", has been Approved on " & FormatDateTime(Date(),2) & "." & vbCrLf
End If
%>
<tr>
<td width="632">
<form ACTION="<%=MM_editAction%>" METHOD="POST" name="form2" id="form2">
<table width="632" border="0">
<tr>
<td colspan="4">test <%= Response.write(variapproval)%> </td>
</tr>
<tr>
<td colspan="4"><textarea name="Reason_for_Request" cols="57" rows="4" id="Reason_for_Request"><%=(Recordset1.Fields.Item("Reason_for_Request").Value)%></textarea></td>
</tr>
<tr>
<td height="45"><input <%If (CStr((Recordset1.Fields.Item("approval").Value)) = CStr("y")) Then Response.Write("CHECKED") : Response.Write("")%> name="approval" type="radio" value="y"/>Approved<br />
<input <%If (CStr((Recordset1.Fields.Item("approval").Value)) = CStr("n")) Then Response.Write("CHECKED") : Response.Write("")%> name="approval" type="radio" value="n"/>Not Approved</td>
<td colspan="3">
<input type="submit" name="Submit" value="Update Record" />
<input type="hidden" name="testapproval" value="<%= Response.write(variapproval)%>">
<input type="hidden" name="MM_update" value="form2">
<input type="hidden" name="MM_recordId" value="<%= Recordset1.Fields.Item("Cerf_ID").Value %>">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</code>

Thanks,
Dan
 
The Response object is an object that contains everything that is going to go back to the user's web browser as well as functions to manipulate that data. It contains a collection of cookies, headers, and a buffer to hold the HTML portion of the response.

The reason this is important is because Response.Write does not work as you think it does. When you issue a Response.Write you are basically saying "send everything in this string back to the end user's browser".

Here is what we are looking at:
Code:
objMessage.TextBody = vbCrLf & Request.Form("testapproval") or Response.write(variapproval)

Here is what it should be (assuming the variable variapproval was set somewhere):
Code:
objMessage.TextBody = vbCrLf & Request.Form("testapproval") or variapproval

Next Problem.
When you assign the output of a conditional statement (like an "or") to a variable or property that is expecting a string, your going to get a string representation of either "True" or "False" (or if your really lucky, "-1" or "0").
What you really want to be doing is another if statement to determine if the test approval field was set to "y". Like o:
Code:
If Request.Form("testapproval") = "y" Then
   objMessage.TextBody = vbCrLf & "Approved: " & Now()
Else
   objMessage.TextBody = vbCrLf & "Approved: Not Approved"
End If

Hope that helps,
-T

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top