This topic is locked

Code works with "after update" but not with a button "serv

5/13/2011 9:01:34 AM
ASPRunnerPro General questions
B
beachldy author

Why does code work in one place and not the other? Any insight would be helpful.
The code below works fine on a form on "After Update" event. I moved the code to a button I added, and put it in the Button's "Server" function, as it seems to be the only place to put vb code. Why doesn't the code work with the button, but does with the form? Is there some kind of "On Click" event on a button that needs to have the code done in the Html editor instead? And if so, would the code below work in HTML with the '<script>' tags?
All I'm wanting to do is have the user click a button to send an email instead of making the form do it automatically....otherwise, there's too many emails going out for every single change made.
------------------------------CODE ---------------------------------------------

'<script type="text/vbscript"> 'Use only if putting in html

**

Const fromEmail = "whomever@gmail.com"

Const password = "mypassword"

'**

Dim CustIDCur, rs, CustName, msg, CustEmail, Stat, DriverName
CustIDCur = values("CustID")
If values("Status") = "Scheduled" then

Stat = "Your Reservation has been added or updated"

ELseif values("Status") = "Cancelled" then

Stat = "Your Reservation has been cancelled :"

End If

CustEmail = values("CustomerEmail")
set rst = dal.Table("tblCustomers").Query("CustID=" & CustIDCur ,"")

CustName = rst("Fname") & " " & rst("LName")

rst.Close:set rst = Nothing
msg = Stat & vbcrlf

msg = msg & "Start: " & DateValue(values("StartDate")) & " " & Timevalue(values("StartTime")) & vbcrlf

msg = msg & "Customer: " & CustName & vbcrlf

msg = msg & "Driver: " & DriverName & vbcrlf

msg = msg & "Location: " & values("PickupAddress") & vbcrlf

msg = msg & "Ends: " & DateValue(values("EndDate")) & " " & TimeValue(values("EndTime"))
Dim emailObj, emailConfig

Set emailObj = CreateObject("CDO.Message")

emailObj.From = "Limo Services and Reservations"

emailObj.To = DriverEmail

emailObj.Subject = "Your Reservation"

emailObj.TextBody = msg
'

'emailObj.AddAttachment WScript.Arguments.Item("attachment.txt")

'
Set emailConfig = emailObj.Configuration

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver";) = "smtp.gmail.com"

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport";) = 465

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing";) = 2

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate";) = 1

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl";) = true

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername";) = fromEmail

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword";) = password

emailConfig.Fields.Update
emailObj.Send
Set emailobj = nothing

Set emailConfig = nothing
End If

'<script> ' use only if putting code in html

Sergey Kornilov admin 5/16/2011

You should not put anything but the actual ASP code there. Remove all the formatting like **