Help assigning 'Now' to a bound or unbound control

T

Terri

I am a newbie to VBScript and I know this should be simple enough but I have
been struggling for two days.

I am trying to assign the Now function to a bound or unbound control on an
Outlook Contact form. I can’t get the bound control to reinitialize and
refresh when the form is reopened and I can’t get the unbound control to
display anything at all.

What is the proper flow and syntax? I am using Outlook 2003.

Any help would be greatly appreciated.

Thank you,
Terri
 
T

Terri

Correction: I see that the bound control is updating during the property
change event but how do I assign it to another bound field?
 
T

Terri

Hi Sue. I have looked over this page a number of times and have been picking
through pages in your book.

I still can't get it to work. I am trying to capture the bound
"DateModified" value in the write event to update the appropiate bound
"??Updated" value. I am using a Select Case to determine which opotion was
picked.

If the IN option was selected then I want the InUpdated field to populate on
save. I am trying use the code:

Set InUpdated = Item.ItemProperties("DateModified")
 
S

Sue Mosher [MVP-Outlook]

Please show more code. How are you instantiating InUpdated?

Also, you can't just make up property names like DateModified. Look up the
exact names in the object browser. LastModificationTime is the name of the
property that holds the modification date. HOWEVER, in your scenario, you
should use Now() as I demonstrated and not try to get the
LastModificationTime, which may not be set yet when Write fires.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
T

Terri

There isn't much code and it is rather muddled as I was trying to get this
portion working before adding validation and such. It is a simple IN OUT
Board with three options IN, OUT and HOME. I want to record the modified
date when the final selection has been made. All of the fields/controls are
bound. One for the option buttons, three for the Last Updated and one for the
Date Modified. These are all user-defined. I guess I really need to read
the book in depth to gain an understanding of everything. I have gotten
accustomed to using Access the last couple of years and rely on many of its
built in capabilities.

Here is what I have:

Option Explicit

Function Item_Open()

'Dim objInsp
'Set objInsp = Item.GetInspector

'Set objPage = objInsp.ModifiedFormPages("Staff Information")

Dim stroptSelected
Dim strDateModified
'Dim DateModified
'Dim InUpdated
Dim OutUpdated
Dim HomeUpdated

End Function


Function Item_Write(ByVal Name)

Select Case Name
Case "optSelected"
stroptSelected = Item.ItemProperties("optSelected")
Select Case stroptSelected
Case "IN"
Item.ItemProperties("InUpdated") = Now
Case "OUT"
Set Item.ItemProperties("OutUpDated") =
Item.ItemProperties("DateModified")
Case "HOME"
Set Item.ItemProperties("HomeUpdated") =
Item.ItemProperties("DateModified")
End Select
End Select

End Function

Function Item_Close(ByVal Name)


End Function
 
S

Sue Mosher [MVP-Outlook]

Did you read the page I suggested? It explains everything you need to know to
perform this operation. Let's go through your code from the top and try to
make some sense out of it.

If that's all the code you have in your declaration section and in the
Item_Open event handler, you can remove the Item_Open code, because it
doesn't actually do anything.

Function Item_Write(ByVal Name)

The only parameter available for the Write event handler is a Cancel
parameter. Always use the Script | Event Handler command to insert the
correct event handler procedure signature.

I can't tell what you're trying to do with the Name parameter. Are you
mixing up the CustomPropertyChange event (discussed on the page I suggested)
with the Write event?

Select Case Name
Case "optSelected"
stroptSelected = Item.ItemProperties("optSelected")

If you really meant to use the CustomPropertyChange event rather than Write,
then Name would be the name of the property that changes. However,
"optSelected" looks like the name of a control, not a property. If
optSelected is the name of a bound control, then you need to be using the
name of the bound property here, not the control name.

Set Item.ItemProperties("OutUpDated") =
Item.ItemProperties("DateModified")

This statement assumes that DateModified is a custom property. Is there such
a property? How is its value set? Why aren't you using Now() as you did with
the InUpdated property? (Same question for the HOME case.) Also, the Set
keyword is used to instantiate an object variable. Do not use it when you are
trying to set the value of a property.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
T

Terri

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’.

The textboxes reflecting the last updated date and time are user defined as
date/time fields, with the values named’ InUpdated’, ‘OutUpdated’, and
‘HomeUpdated’.

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.

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 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.

Here is the code I am now trying to work with:

Sub CheckOptionUpdated()

Select Case "optSelected"
Case "optIN"
Item.ItemProperties("InUpdated") = Now
Case "optOUT"
ItemProperties("OutUpDated") = Now
Case "optHOME"
Item.ItemProperties("HomeUpdated") = Now
End Select

End Sub

Function Item_Write()
Call CheckOptionUpdated
End Function
 
S

Sue Mosher [MVP-Outlook]

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.
 
T

Terri

Print screens would be helpful and yes I am still confused.

The group of option buttons have the names optIN etc and they are all bound
to the field 'optSelected' The values of the field are IN, OUT and HOME.

I tried using an If statement in the write event also without success.
 
S

Sue Mosher [MVP-Outlook]

We don't need print screens if you provide a detailed and accurate
description of what is a field and what is a control. If optSelected is the
name of a custom property (NOT a control -, you've confirmed that optSelected
is on the All Fields page, right?), you can go back to the article I
suggested and look again at the syntax for referring to a custom property. In
fact, you already know it, because you've used ItemProperties in your code
already. I'd use UserProperties instead, to make it obvious that the code is
dealing with a custom property, but it's essentially the same syntax:

Item.UserProperties("optSelected")

That's the value that needs to be tested in the Select Case statement. The
values in the individual Case statements then need to reflect the possible
values that custom property can have. In this case, those would be the values
associated with each option button in the group:

Select Case Item.UserProperties("optSelected")
Case "IN"
Item.UserProperties("InUpdated") = Now()
Case "OUT"
Item.UserProperties("OutUpDated") = Now()
Case "HOME"
Item.UserProperties("HomeUpdated") = Now()
End Select

You might find the additional information on option buttons at
http://www.outlookcode.com/article.aspx?ID=32 useful.

I would also suggest that next time, you use a name for your custom field
that is less likely to be confused with a control name. For example,
OptionSelected would be a better field name than optSelected.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
T

Terri

Hi Sue. I finally got it working. I could have sworn I tried it that way
but I must have missed something.

Thank you very much for your assistance and patience! I truly appreciate it.

Now on to validation...
 

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