Custom Contact Form how to update when loaded.

Roland Askew

New Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
I have created a custom contact form which calculated the contact age based on their date of birth. The age is stored in a user defined field and I use the normal date of birth field. All this works perfectly when creating the contact the problem is when you open the contact later the age field does not to their current age. If a year later you open the contact then their age should be one year greater however this does not happen until one of the fields is changed and the property change event is run. Then it calculates the age correctly.

Is there anyway to run this event when the form is loaded or how would I run the repaint if that would work.

I currently have a poor work around by using the form opening event and changing a field using vba and then changing it back.

Thanks for any help anyone can give and if needed I am using Outlook 2016.

Roland
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Are you using code or a custom field with a formula? If you use code, you need to use item_open, not on property change. With custom field, you need to set the field to update automatically.

To calculate the age of an Outlook contact has a sample that updates.
 

Roland Askew

New Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
Thank you for the two replies.

I am using a custom field with a formula and I have the field to update automatically. The problem is that it does not automatically update when the form is loaded. Is the update automatically suppose to run when the form is opened? However, as soon as I change anything on the contact then the field does update and the correct age is shown. I assume that the property change event does this.

Is there away to run the property change event when opening the form? As a work around I have in the opening form event vbscript which changes one of the fields and then changes it back and that seems to set the update event off.

Otherwise, I think the alternative is to use code for to check the field and run this in both the open event and the property change event.

Any suggestions on how better to do this would be much appreciated.
Thanks
Roland
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I don't know if its a problem with newer versions or something else (and i can't find my really old form to see if it works in 2016 or refresh my memory to see if the age updated automatically there)... but my version of your method works - i have a hidden text box set to have 'now' as the value and use this the item_open script to clear the field then save it.
Code:
Sub Item_Open()
  Set FormPage = Item.GetInspector.ModifiedFormPages("Contact Age")
  Set TextBox4 = FormPage.Controls("TextBox4")
  TextBox4.value = "None"
Item.save
End Sub
fields.png




(if you use a field in the view, it should update when you leave the folder and come back. )
 

Roland Askew

New Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
Hi Diane
Thank you for taking the time to help me with this due to ease I have gone with updating the Opening event on the form with code that checks the field as follows

Function Item_Open()
If Item.Birthday = #1/1/4501# Then
Item.UserProperties.item("Age Client") = 0​
Else
If Date() >= DateSerial(Year(Date()),Month(Item.Birthday),Day(Item.Birthday)) Then
Item.UserProperties.item("Age Client")=Year( Date()) - Year(Item.Birthday)​
Else
Item.UserProperties.item("Age Client")=Year( Date()) - Year(Item.Birthday) - 1​
End If​
End if
Item.Save
End Function

This seems to work ok and has the advantage of not needing to create new text field.

Thanks again yours and Michael knowledge and help is invaluable as always.
Roland
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
As long as it works. :) In my case, i used the longer age function and didn't want to convert the long formula to the script - forcing an update was easier.
 
Top