This topic is locked
[SOLVED]

 If Statement Inside Email Body

8/23/2011 9:53:36 AM
ASPRunnerPro General questions
J
Jay123 author

Hi!
I would like to ask what the correct syntax is for an if statement inside an email body. If I want to include the value of the field (let's say field2) in my email if that field is not empty or blank, could you pls. let me know what the correct syntax is?
Here's the code that I always include to send out an email after the save button is clicked.

==============================================================

myMail.TextBody="Hello!" & vbcrlf& vbcrlf&

values("field1") & vbcrlf&


' what is the syntax if field2 is not empty or blank?

' I thought this would work --> if values("field2") <> "" then values("field2") end if

values("field3") & vbcrlf&_

"Thanks"

==============================================================
Thanks,

Jay

Sergey Kornilov admin 8/23/2011

No, it won't work this way.
Sample code:

message = message & "Hello there"

if values("field2") <> "" then

message = message & values("field2")

end if
J
Jay123 author 8/23/2011

Thanks, Sergey.
My scenario is I have more than 20 fields to evaluate so I am going to have thousands of if statement (combination) if I am going to do it that way.
Do you have other solution for that? Let's say 3 or 5 or 10 or 15 will not be blank/empty out of more than 20 fields?
Thanks,

Jay

Sergey Kornilov admin 8/23/2011

Not sure I understand how 20 fields can produce a thousand of IFs. 20 IFs, maybe.
I guess you need to elaborate it a little bit.

J
Jay123 author 8/23/2011

Hi Sergey,
To evaluate each field of the 20 fields, I have to create 20 if statement right away (one for each field). If I am going to do a combination (let's say for field1 and field2), that would be another if statement like this.

===========================================================

message = message & "Hello there"

if values("field1") <> "" AND values("field2") <> "" then

message = message & values("field1") & values("field2")

end if

===========================================================
For every combination of fields, I have to create an if statement since the user can select between 1 and 20 fields.
Do you have any suggestions on how can I eliminate the if statement for all those combinations?
Thanks,

Jay

Sergey Kornilov admin 8/23/2011

Jay,
you do not need any combinations. 20 IFs is all you need.

message = message & "Hello there"

if values("field1") <> "" then

message = message & values("field1")

end if

if values("field2") <> "" then

message = message & values("field2")

end if

...
J
Jay123 author 8/24/2011

Thanks, Sergey.