This topic is locked

Sending e-mail only if value is selected in specific combo box

1/15/2007 11:49:46 AM
ASPRunnerPro General questions
orit author

I have a delegateTo field, with which I want the manager to select which of his employees will approve specific item.

I added the delegateTo field to the _edit page and I want that if the uesr selects value from the list of users in the delegateTo field (combo box), an e-mail with specific message will be sent to the e-mail of the selected user (the e-mail is stored in a separate table, that is the source to the combo box lookup wizard). If a value wasn't selected in the delegateTo field. an e-mail will not be sent.
How to do that?
In addition, I want that after the e-mail is sent, the value of the field will be initialized\reset\cleaned. How to do that?
Thanks a lot

Sergey Kornilov admin 1/15/2007

Use BeforeEdit event:

if dict("delegateTo")<>"" then

... send an email
dict("delegateTo") = ""

end if
orit author 1/16/2007

Thanks a lot.
3 Questions:

  1. When I add the following code in order to reset the Delegate to field:

dict("fileMDelegateTo") = ""



so my code looks like:

Function BeforeAdd(dict)
' Parameters:

' dict - Scripting.Dictionary object.

' Each field on the Add form represented as 'Field name'-'Field value' pair
'********** Send email with new data ************

' do not forget to setup email parameters like From, SMTP server etc

' on 'Security->User login settings' dialog

BeforeAdd = True

if dict("fileMDelegateTo")<> "" then
message ="Please review the document: " & dict("fileTitle") & vbcrlf



email="orit_itzhar@atrica.com"

subject="Your Approval is Required"

cFrom="orit_itzhar@gmail.com"



sendmail email, subject, message
dict("fileMDelegateTo")= ""
BeforeAdd = True
' set BeforeAdd to True if you like to proceed with adding new record

' set it to False in other case

End if

End Function



I get the error:

<<< Record was NOT updated >>>
[Microsoft][ODBC Microsoft Access Driver]Error in row
An e-mail is sent but the record is not added to the database.

What is the problem and how to solve it?
2. I want that the "to" (email) e-mail will be taken automatically according the selected user in the delegate to (fileMDelegateTo) combo box from the "users" table that holds the userID, userName and userMail. How to do that?
3. I want that the "from" (cFrom) field will be taken automatically according the logged in user from the userMail field in the same "users" table. How to do that?
Thanks a lot

Sergey Kornilov admin 1/16/2007

Make sure fileMDelegateTo field allows empty values.
Add the code that pulls user's data from Users table like EmalTo, EmailFrom etc.
sendmail function do not support EmailFrom. You need to use your own email routine in order to specify From Email.

orit author 1/16/2007

After I allowed zero length for fileMDelegateTo it worked! Thanks

Add the code that pulls user's data from Users table like EmalTo, EmailFrom etc.


Can you please provide more details or give an example?
Thanks a lot

Sergey Kornilov admin 1/16/2007

I can recommend to check the following two articles:

http://www.webcheatsheet.com/asp/database_connection.php - how to open and use recordset in ASP

http://www.webcheatsheet.com/sql/interacti.../sql_select.php - how to write SELECT SQL statements
You came to the point where some basic ASP and SQL knowledge is required.