item.userpropterties

J

Joel

Hi,

I am doing this and it runs very very slow:

..........
Sub Item_CustomPropertyChange(ByVal strName)
Set prps = Item.UserProperties
If prps("HeatBarrier") = "True" Then
.........


For every If prps....... statement I add, my form runs slower and slower.
Can anybody suggest an alternative method to speed it up.

I tried If Item.UserProperties("HeatBarrier") then
......

but it's even slower. Please help. THANK YOU. - Joel
 
S

Sue Mosher [MVP-Outlook]

The way you have it written, all your code is running any time any custom
property changes. Instead, use a Select Case block to work with only the
properties you're interested in:

Sub Item_CustomPropertyChange(ByVal Name)
Select Case Name
Case "HeatBarrier"
If Item.UserProperties("HeatBarrier") = True Then
' your code goes here
End If
Case "anotherpropname"
End Select
End Sub

See http://www.outlookcode.com/d/propsyntax.htm for more information on this
event.

Note that if HeatBarrier is a Yes/No property, the allowable values are the
logical constants True and False not the string values "True" and "False."
 
J

Joel

Sue,

Thank you so much! That was a major problem I had.
Does your book cover issues like this? I think I'm going to get it.
-J
 
J

Joel

Sue, This works great. But still takes 2 seconds when tabbing from field
to field. Perhaps there is a better way to write it? Can you please make a
suggestion? This is how I wrote it:

Dim GlobalHeatbarrier
Dim GlobalProductResultB

Sub Item_CustomPropertyChange(ByVal strName)

Select Case GlobalHeatbarrier
Case "HeatBarrier"
End Select
If Item.UserProperties("HeatBarrier") = True Then
Select Case GlobalProductResultB
Case "ProductResultB"
End Select
Item.UserProperties("ProductResultB") = "B"
End If

End Sub

Thanks -Joel
 
D

Duncan McCreadie

You are using too many Select ... Case ... End Select clauses. As Sue (and
I in a different thread) suggested you should be using a single Select
clause to detect a change in the custom property e.g.

Select Case strName ' assumes that all the fields you are concerned with are
UserProperties

Case "HeatBarrier"
If Item.UserProperties(strName) Then
End If
Case "GlobalProductResultB"
If Item.UserProperties(strName) = "B" then
End If
Case.....



End Select


HTH

Duncan
 
S

Sue Mosher [MVP-Outlook]

You haven't really changed anything because your Select Case statement isn't
working with the argument passed by the event handler (i.e. Name).
Therefore, all your code is still running every time any custom property
changes.

This is exactly the kind of basic concept that my book covers, but it can
still be hard to "get." Try this, so you see how the CustomPropertyChange
event works:

Sub Item_CustomPropertyCHange(ByVal Name)
MsgBox Name
End SUb

Now go back and look again at the structure of the Select Case block in my
earlier message. See how the code to handle the "HeatBarrier" property is
*inside* the Select Case block. All you need to do is add -- at the 'your
code goes here' statement -- the code that you want to use to handle a
change in the HeatBarrier property.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
J

Joel

Sue/Duncan,

Thank you both for your help. That was a good example Sue.
I tried this, keeping my propery inside the select case block.
My goal is to change the property value of ProductResultB to B if property
value HeatBarrier is checked.
Sub Item_CustomPropertyChange(ByVal Name)

Select Case Name
Case "HeatBarrier"
If Item.UserProperties("HeatBarrier") = True Then
Case "ProductResultB"
Item.UserProperties("ProductResultB") = "B"
End If
End Select

End Sub


It gives me an error - Expected statement Line 6. Please help. Much thanks
as always!

-Joel
 
S

Sue Mosher [MVP-Outlook]

You have an extraneous Case statement in the middle of your If ... Then ...
End If block. Remove it.

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

Duncan McCreadie

Your problem remains a misunderstanding of the Select Case...End Select
Structure.

Try this

Sub Item_CustomPropertyChange(ByVal Name)

Select Case Name
Case "HeatBarrier"
If Item.UserProperties("HeatBarrier") = True Then
Item.UserProperties("ProductResultB") = "B"
End If
End Select

End Sub

Duncan
www.contactree.com
 
J

Joel

Thank you Duncan. It worked, but why do I not need this?:

Case "ProductResultB"

Thanks again, all of you are very helpful.
-Joel
 
D

Duncan McCreadie

You don't! Sue and I assumed that you were looking for a change in
ProductResultB, hence the Case statement, whereas you are merely setting its
value based on a change in the value of "HeatBarrier".

The Select Case clause is used to choose a single option from many possible
(but exclusive) options, which is why it is faster than multiple If ..End If
statements, as once a matching condition is found, no other conditions are
evaluated.

Duncan
www.contactree.com
 
J

Joel

Thanks! Can you use it in a 2 if statement situation? Would this be
right?:

Sub Item_CustomPropertyChange(ByVal Name)

Select Case Name
Case "HeatBarrier"
If Item.UserProperties("HeatBarrier") = True Then
Case "AnotherProperty"
If Item.UserProperties("AnotherProperty") = True Then
Item.UserProperties("ProductResultB") = "B"
End If
End If
End Select

End Sub

Is Case "AnotherProperty" needed?

Thanks again,
-Joel
 
D

Duncan McCreadie

Not like that you can't - a correct version syntactically would be:

Sub Item_CustomPropertyChange(ByVal Name)

Select Case Name
Case "HeatBarrier"
If Item.UserProperties("HeatBarrier") = True And
Item.UserProperties("AnotherProperty") = True Then
Item.UserProperties("ProductResultB") = "B"
End If
Case "AnotherProperty"
If Item.UserProperties("HeatBarrier") = True And
Item.UserProperties("AnotherProperty") = True Then
Item.UserProperties("ProductResultB") = "B"
End If
End Select

End Sub

This covers the situation where you need both custom properties to be true
for ProductResultB to be "B" and both properties can be changed using the
form.

If this still isn't clear then you may want to post the whole subroutine
that you are trying to optimise to me direct and I will do what I can.

Duncan
 

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