Setting Initial Value in Contact Form

A

AndrewA

I have created a custom form for a contacts database with
a new field called ParentCompany. My intention that this
will contain the name of the parent company for the
contact's Company. If the contact actually works for the
parent company then ParentCompany should equal Company by
default. I have tried to set this up by setting the
initial value formula to be [company] (in
Properties/Value) and this seems to work but I cannot
then overwrite it with a different value if there is a
different Parent company.

Essentially what I want to do is: if nothing supplied
then [ParentCompany]=[Company] otherwise if a value is
supplied for [ParentCompany] then use the supplied value.

Thanks in advance Andrew
 
S

Sue Mosher [MVP-Outlook]

You can't do that with a formula field, because a formula field always sets
the value based on the formula; no override is possible.

Using a formula to set the initial value won't work either, because the
Company field in a new, blank contact is blank.

What you can do is use is the PropertyChange event to automatically set the
value for the ParentCompany field, but only if it's blank:

Sub Item_PropertyChange(ByVal Name)
Select Case Name
Case "CompanyName"
If Item.UserProperties("ParentCompany") = "" Then
Item.UserProperties("ParentCompany") = Item.CompanyName
End If
End Select
End Sub

See http://www.outlookcode.com/d/propsyntax.htm for more information on
using the PropertyChange event.
 
S

Sue Mosher [MVP-Outlook]

Be realistic: If you're going to work with Outlook forms, you're going to
have to write code. This isn't power programming. Open the contact in design
mode, click Form | View Code, then paste in the code I already provided. But
please, please, go to the URL I suggested and take the time to learn about
what you're doing.

Validation formulas stop the user from saving an item if criteria have not
been met. Value formulas set the value of a field either initially or
always, with no ability for the user to override in the latter case. Neither
fits the scenario you described.

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



Andrew A said:
Sue

I really appreciate your assistance. Problem is I have never programmed
in Outlook and I have no idea where to start. Can you direct me to an
online reference that could get me started. Chances are that I will never
have a need to do something like this again so I don't want to have to learn
power programmer stuff (unless it is fairly quick and simple). I really
wanted a very simple solution that didn't require anything out side of
native Outlook. I had thought that the built in validation controls would
do what I wanted but that doesn't appear to be the case.
Thanks again

Andrew

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

You can't do that with a formula field, because a formula field always sets
the value based on the formula; no override is possible.

Using a formula to set the initial value won't work either, because the
Company field in a new, blank contact is blank.

What you can do is use is the PropertyChange event to automatically set the
value for the ParentCompany field, but only if it's blank:

Sub Item_PropertyChange(ByVal Name)
Select Case Name
Case "CompanyName"
If Item.UserProperties("ParentCompany") = "" Then
Item.UserProperties("ParentCompany") = Item.CompanyName
End If
End Select
End Sub

See http://www.outlookcode.com/d/propsyntax.htm for more information on
using the PropertyChange event.
AndrewA said:
I have created a custom form for a contacts database with
a new field called ParentCompany. My intention that this
will contain the name of the parent company for the
contact's Company. If the contact actually works for the
parent company then ParentCompany should equal Company by
default. I have tried to set this up by setting the
initial value formula to be [company] (in
Properties/Value) and this seems to work but I cannot
then overwrite it with a different value if there is a
different Parent company.
Essentially what I want to do is: if nothing supplied
then [ParentCompany]=[Company] otherwise if a value is
supplied for [ParentCompany] then use the supplied value.
Thanks in advance Andrew
 
A

Andrew A

Thanks Sue. I'm here to learn and I hear you. AA
-----Original Message-----
Be realistic: If you're going to work with Outlook forms, you're going to
have to write code. This isn't power programming. Open the contact in design
mode, click Form | View Code, then paste in the code I already provided. But
please, please, go to the URL I suggested and take the time to learn about
what you're doing.

Validation formulas stop the user from saving an item if criteria have not
been met. Value formulas set the value of a field either initially or
always, with no ability for the user to override in the latter case. Neither
fits the scenario you described.

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



Sue

I really appreciate your assistance. Problem is I
have never programmed
in Outlook and I have no idea where to start. Can you direct me to an
online reference that could get me started. Chances are that I will never
have a need to do something like this again so I don't want to have to learn
power programmer stuff (unless it is fairly quick and simple). I really
wanted a very simple solution that didn't require anything out side of
native Outlook. I had thought that the built in validation controls would
do what I wanted but that doesn't appear to be the case.
Thanks again

Andrew

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

You can't do that with a formula field, because a
formula field
always sets
the value based on the formula; no override is possible.

Using a formula to set the initial value won't
work either, because
the
Company field in a new, blank contact is blank.

What you can do is use is the PropertyChange
event to automatically
set the
value for the ParentCompany field, but only if it's blank:

Sub Item_PropertyChange(ByVal Name)
Select Case Name
Case "CompanyName"
If Item.UserProperties ("ParentCompany") = "" Then
Item.UserProperties
("ParentCompany") =
Item.CompanyName
for more information
on
using the PropertyChange event.
I have created a custom form for a contacts database with
a new field called ParentCompany. My intention that this
will contain the name of the parent company for the
contact's Company. If the contact actually works for the
parent company then ParentCompany should equal Company by
default. I have tried to set this up by setting the
initial value formula to be [company] (in
Properties/Value) and this seems to work but I cannot
then overwrite it with a different value if there is a
different Parent company.
Essentially what I want to do is: if nothing supplied
then [ParentCompany]=[Company] otherwise if a value is
supplied for [ParentCompany] then use the supplied value.
Thanks in advance Andrew


.
 
A

Andrew A

Sue, I did exactly what you said and it worked.
Thanks. BTW, in your script you use "CompanyName". The
field in the Outlook fields list is called "Company"
which is what I would have thought should be included in
the script. (I actually tried it and it didn't work!!)
Can you explain this? AA
-----Original Message-----
Be realistic: If you're going to work with Outlook forms, you're going to
have to write code. This isn't power programming. Open the contact in design
mode, click Form | View Code, then paste in the code I already provided. But
please, please, go to the URL I suggested and take the time to learn about
what you're doing.

Validation formulas stop the user from saving an item if criteria have not
been met. Value formulas set the value of a field either initially or
always, with no ability for the user to override in the latter case. Neither
fits the scenario you described.

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



Sue

I really appreciate your assistance. Problem is I
have never programmed
in Outlook and I have no idea where to start. Can you direct me to an
online reference that could get me started. Chances are that I will never
have a need to do something like this again so I don't want to have to learn
power programmer stuff (unless it is fairly quick and simple). I really
wanted a very simple solution that didn't require anything out side of
native Outlook. I had thought that the built in validation controls would
do what I wanted but that doesn't appear to be the case.
Thanks again

Andrew

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

You can't do that with a formula field, because a
formula field
always sets
the value based on the formula; no override is possible.

Using a formula to set the initial value won't
work either, because
the
Company field in a new, blank contact is blank.

What you can do is use is the PropertyChange
event to automatically
set the
value for the ParentCompany field, but only if it's blank:

Sub Item_PropertyChange(ByVal Name)
Select Case Name
Case "CompanyName"
If Item.UserProperties ("ParentCompany") = "" Then
Item.UserProperties
("ParentCompany") =
Item.CompanyName
for more information
on
using the PropertyChange event.
I have created a custom form for a contacts database with
a new field called ParentCompany. My intention that this
will contain the name of the parent company for the
contact's Company. If the contact actually works for the
parent company then ParentCompany should equal Company by
default. I have tried to set this up by setting the
initial value formula to be [company] (in
Properties/Value) and this seems to work but I cannot
then overwrite it with a different value if there is a
different Parent company.
Essentially what I want to do is: if nothing supplied
then [ParentCompany]=[Company] otherwise if a value is
supplied for [ParentCompany] then use the supplied value.
Thanks in advance Andrew


.
 
S

Sue Mosher [MVP-Outlook]

When in doubt about actual property names, check the object browser: Press
ALt+F11 to open the VBA environment in Outlook, then press F2.


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



Andrew A said:
Sue, I did exactly what you said and it worked.
Thanks. BTW, in your script you use "CompanyName". The
field in the Outlook fields list is called "Company"
which is what I would have thought should be included in
the script. (I actually tried it and it didn't work!!)
Can you explain this? AA
-----Original Message-----
Be realistic: If you're going to work with Outlook forms, you're going to
have to write code. This isn't power programming. Open the contact in design
mode, click Form | View Code, then paste in the code I already provided. But
please, please, go to the URL I suggested and take the time to learn about
what you're doing.

Validation formulas stop the user from saving an item if criteria have not
been met. Value formulas set the value of a field either initially or
always, with no ability for the user to override in the latter case. Neither
fits the scenario you described.

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



Sue

I really appreciate your assistance. Problem is I
have never programmed
in Outlook and I have no idea where to start. Can you direct me to an
online reference that could get me started. Chances are that I will never
have a need to do something like this again so I don't want to have to learn
power programmer stuff (unless it is fairly quick and simple). I really
wanted a very simple solution that didn't require anything out side of
native Outlook. I had thought that the built in validation controls would
do what I wanted but that doesn't appear to be the case.
Thanks again

Andrew

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

You can't do that with a formula field, because a
formula field
always sets
the value based on the formula; no override is possible.

Using a formula to set the initial value won't
work either, because
the
Company field in a new, blank contact is blank.

What you can do is use is the PropertyChange
event to automatically
set the
value for the ParentCompany field, but only if it's blank:

Sub Item_PropertyChange(ByVal Name)
Select Case Name
Case "CompanyName"
If Item.UserProperties ("ParentCompany") = "" Then
Item.UserProperties
("ParentCompany") =
Item.CompanyName
for more information
on
using the PropertyChange event.
I have created a custom form for a contacts database with
a new field called ParentCompany. My intention that this
will contain the name of the parent company for the
contact's Company. If the contact actually works for the
parent company then ParentCompany should equal Company by
default. I have tried to set this up by setting the
initial value formula to be [company] (in
Properties/Value) and this seems to work but I cannot
then overwrite it with a different value if there is a
different Parent company.
Essentially what I want to do is: if nothing supplied
then [ParentCompany]=[Company] otherwise if a value is
supplied for [ParentCompany] then use the supplied value.
Thanks in advance Andrew


.
 

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