Comments inline.
Terri said:
Hi Sue. I am back at it again and still having some difficulties.
To clarify, ‘optSelected’ is the name of the user-defined control and the
values are ‘IN’, ‘OUT’ and ‘HOME’. The name of each field is ‘optIN’,
‘optOUT’ and ‘optHOME’.
I think there's still some confusion here between controls and properties
(also known as fields). "User-defined control" isn't a term we use in Outlook
programming. A control is a UI element on a form design surface. It can be
either bound to an Outlook property or unbound. If it is bound, then the
proper way to access the value of the property is through the UserProperties
collection.
Not only optSelected, but also optIN, optOUT, and optHOME sound like the
names of controls, not the names of custom Outlook properties. You can see
the custom properties defined for the form in the (All Fields) tab under
"User-defined fields in this item." Do you see these field names there?
Also, the "opt" prefix makes me wonder if you're referring not to a single
control but to a group of option buttons. So, I think that before we can make
much progress, we need more information from you to clear up this issue of
controls vs. fields. If you have a bound control, we need to know the name of
the field it is bound to, and possibly also the data type for that field.
You can look on the Value tab of the control's Properties dialog to see what
field -- if any -- it is bound to.
The textboxes reflecting the last updated date and time are user defined as
date/time fields, with the values named’ InUpdated’, ‘OutUpdated’, and
‘HomeUpdated’.
By "values," do you mean the names of the text box controls? Or, with an eye
toward the same kind of confusion as discussed above, the names of custom
Outlook properties bound to those controls?
I created a separate textbox named 'DateModified' with a user-defined value
of 'CurrentDateTime' as a date/time field with a default value of ‘Now’ using
an automatic calculation. I am no longer using this.
So, if you're not using, we can completely ignore both the text box named
"DateModified" and the custom field ("user-defined value" is not the right
terminology) named "CurrentDateTime," right?
I didn't want the ‘??Updated’ date field to populate until the Save (Write)
event took place in case the wrong selection was made and then changed to the
correct option before saving. That is why I tried to determine this in the
write event.
I don't think "??Updated" is a valid name for a custom property. Are you
referring to the InUpdated, OutUpdated, and HomeUpdated fields in the code
below?
The Write event is the correct event to use.
I thought I should then accomplish this with a sub routine called from the
write event to determine which option was selected and then the appropriate
‘??updated’ field have the current date and time written to it.
That's a good, modular approach, in theory, but the implementation is off,
partly because of the confusion over controls and fields discussed above, but
also because of a major syntax/logic problem.
Here is the code I am now trying to work with:
Sub CheckOptionUpdated()
Select Case "optSelected"
The above statement is the reason why this code won't work. A Select Case
cannot have a string literal in it, which is what "optSelected." It needs
some variable or object property that can be evaluated for a specific value
and then matched with one of the Case statements inside the Select Case
block. We can't get any farther without knowing exactly what optSelected,
optIN, optOUT, and optHOME are, as discussed above.
Case "optIN"
Item.ItemProperties("InUpdated") = Now
Now() would be better than Now, but ItemProperties is fine. It's
interchangeable with UserProperties in this usage.
Case "optOUT"
ItemProperties("OutUpDated") = Now
Case "optHOME"
Item.ItemProperties("HomeUpdated") = Now
End Select
End Sub
Function Item_Write()
You still need to do as I suggested and use the Script | Event Handler
command to insert the correct procedure definition for the Item_Write event
handler. This might work, but it really needs the Cancel parameter.