VBScript and IIF function

G

Guest

I have several custom fields on an appointment form. I would like to insert text into the body portion of the appointment, based on the value of a few of these fields. If I use the following code

Body = "Client - " & Item.UserProperties("Client") it works fine. If I try to make it conditional with

Body = "Client - " & IIf(Item.UserProperties("Client") = "Sue Offender","Sue","Other") I get a Type Mismatch error. I would like to use the IIF function with Text or Number or Yes/No type fields and am getting this error with any of them. How can I correct my code

Thanks - Judy Scofiel
 
S

Sue Mosher [MVP-Outlook]

VBScript doesn't support the IIf() function. You need to use something like:

Public Function IIf(blnExpression, vTrueResult, vFalseResult)
If blnExpression Then
IIf = vTrueResult
Else
IIf = vFalseResult
End If
End Function

(from http://www.developerfusion.com/show/1606/)

blnExpression of course must be an expression that evaluates to True or
False.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Judy Scofield said:
I have several custom fields on an appointment form. I would like to
insert text into the body portion of the appointment, based on the value of
a few of these fields. If I use the following code:
Body = "Client - " & Item.UserProperties("Client") it works fine.
If I try to make it conditional with:
Body = "Client - " & IIf(Item.UserProperties("Client") = "Sue
Offender","Sue","Other") I get a Type Mismatch error. I would like to
use the IIF function with Text or Number or Yes/No type fields and am
getting this error with any of them. How can I correct my code?
 
G

Guest

This works great. Another question. If I put my code in the Item_Close event, it doesn't save what I want in the body. If I put it in the Item_CustomPropertyChange(ByVal PropertyName) and use a Select Case for the property name that I want, it works, but seems to iterate through the code many times, slowing down response. If I put it in Item_Open, the user has to save and reopen the item to get the desired result

What do you suggest

Judy Scofiel


----- Sue Mosher [MVP-Outlook] wrote: ----

VBScript doesn't support the IIf() function. You need to use something like

Public Function IIf(blnExpression, vTrueResult, vFalseResult
If blnExpression The
IIf = vTrueResul
Els
IIf = vFalseResul
End I
End Functio

(from http://www.developerfusion.com/show/1606/

blnExpression of course must be an expression that evaluates to True o
False

--
Sue Mosher, Outlook MV
Author o
Microsoft Outlook Programming - Jumpstart fo
Administrators, Power Users, and Developer
http://www.outlookcode.com/jumpstart.asp


Judy Scofield said:
I have several custom fields on an appointment form. I would like t
insert text into the body portion of the appointment, based on the value o
a few of these fields. If I use the following codeOffender","Sue","Other") I get a Type Mismatch error. I would like t
use the IIF function with Text or Number or Yes/No type fields and a
getting this error with any of them. How can I correct my code
 
S

Sue Mosher [MVP-Outlook]

When you use CustomPropertyChange, use a Select Case block to make sure that
you're processing only the property changes you're interested in. See
http://www.outlookcode.com/d/propsyntax.htm

Did you try using Item_Write? That event handler runs whenever the user
saves the item.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Judy Scofield said:
This works great. Another question. If I put my code in the Item_Close
event, it doesn't save what I want in the body. If I put it in the
Item_CustomPropertyChange(ByVal PropertyName) and use a Select Case for the
property name that I want, it works, but seems to iterate through the code
many times, slowing down response. If I put it in Item_Open, the user has
to save and reopen the item to get the desired result.
What do you suggest?

Judy Scofield


----- Sue Mosher [MVP-Outlook] wrote: -----

VBScript doesn't support the IIf() function. You need to use something like:

Public Function IIf(blnExpression, vTrueResult, vFalseResult)
If blnExpression Then
IIf = vTrueResult
Else
IIf = vFalseResult
End If
End Function

(from http://www.developerfusion.com/show/1606/)

blnExpression of course must be an expression that evaluates to True or
False.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Judy Scofield said:
I have several custom fields on an appointment form. I would like
to
insert text into the body portion of the appointment, based on the value of
a few of these fields. If I use the following code: fine.
If I try to make it conditional with:Offender","Sue","Other") I get a Type Mismatch error. I would like to
use the IIF function with Text or Number or Yes/No type fields and am
getting this error with any of them. How can I correct my code?
 
S

Sue Mosher [MVP-Outlook]

Your Select statement needs to be using the argument passed by the event
handler. Read the page I suggested again and use the syntax in the example
there.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Judy Scofield said:
I do have a select case in the CustomPropertyChange:

Sub Item_CustomPropertyChange(ByVal PropertyName)

Select Case PropertyName
Case "Client"
Code
End Select
End Sub

Using the Item_Write works very well.

Judy Scofield

----- Sue Mosher [MVP-Outlook] wrote: -----

When you use CustomPropertyChange, use a Select Case block to make sure that
you're processing only the property changes you're interested in. See
http://www.outlookcode.com/d/propsyntax.htm

Did you try using Item_Write? That event handler runs whenever the user
saves the item.
Judy Scofield said:
This works great. Another question. If I put my code in the
Item_Close
event, it doesn't save what I want in the body. If I put it in the
Item_CustomPropertyChange(ByVal PropertyName) and use a Select Case for the
property name that I want, it works, but seems to iterate through the code
many times, slowing down response. If I put it in Item_Open, the user has
to save and reopen the item to get the desired result.
What do you suggest?
Judy Scofield
----- Sue Mosher [MVP-Outlook] wrote: -----
VBScript doesn't support the IIf() function. You need to use something like:
Public Function IIf(blnExpression, vTrueResult, vFalseResult)
If blnExpression Then
IIf = vTrueResult
Else
IIf = vFalseResult
End If
End Function
(from http://www.developerfusion.com/show/1606/)
blnExpression of course must be an expression that evaluates
to True
or
False.
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
like
to
insert text into the body portion of the appointment, based on
the
value of
a few of these fields. If I use the following code:
works
fine.
If I try to make it conditional with:
Offender","Sue","Other") I get a Type Mismatch error. I
would
like to
use the IIF function with Text or Number or Yes/No type fields and am
getting this error with any of them. How can I correct my code?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top