#2: A bound control is one that is associated with an Outlook property. In other words, the control is bound to the property, so that the control displays the value of the property and the property saves the value entered in the control.
My interpretation of a bound box was if there was code behind the form
telling the checkbox what to do, it was bound.
The other thought was that a bound box was where you had a chosen field
under the properties > value tab, it was bound.
Which one is correct??
Corey
Sue Mosher [MVP-Outlook] wrote:
CheckBox1 etc. sounds like a control name, not an Outlook custom property name. UserProperties is an Outlook object model collection. THerefore, it takes as its argument the name of a custom Outlook property, specifically the property bound to that check box. If you are not using bound controls, then see
http://www.outlookcode.com/d/propsyntax.htm#unbound for the syntax to get a property value from a control.
Sue~
Once I put in the strBody entries, none of the checkboxes are
transferring now.
Receiving a VB Run Time Error : Object variable not set. (Starting at
Line 3)
I inserted 2 note fields to explain my setup for you.
Can't continue further on.
______________________________________________________________________________________________________
Here's my code.
1 Sub Item_Send()
2 strBody = Item.Body
' NOTE: CheckBox1 is the actual name in the properties
3 If Item.UserProperties ("CheckBox1") = True Then
4 strBody = strBody & vbCrLf & "Please Call"
' NOTE: Please call is in the Caption Field
5 End If
6 If Item.UserProperties ("CheckBox2") = True Then
7 strBody = strBody & vbCrLf & "Returned Your Call"
8 End If
9 If Item.UserProperties ("CheckBox3") = True Then
10 strBody = strBody & vbCrLf & "Special Attention"
11 End If
12 If Item.UserProperties ("CheckBox4") = True Then
13 strBody = strBody & vbCrLf & "Confidential"
14 End If
15 If Item.UserProperties ("CheckBox5") = True Then
16 strBody = strBody & vbCrLf & "Rush"
17 End If
18 If Item.UserProperties ("CheckBox6") = True Then
19 strBody = strBody & vbCrLf & "Telephoned"
20 End If
21 If Item.UserProperties ("CheckBox7") = True Then
22 strBody = strBody & vbCrLf & "Wants to See You"
23 End If
24 If Item.UserProperties ("CheckBox8") = True Then
25 strBody = strBody & vbCrLf & "Will Call Again"
26 End If
27 If Item.UserProperties ("CheckBox9") = True Then
28 strBody = strBody & vbCrLf & "Came to See You"
29 End If
30 Item.Body = strBody
31 End Sub
Here are the PROPERTIES of the checkbox:
Display Tab (Tab 1)
NAME: CheckBox1
Caption: Came to See You
Settings: Visible, Enabled, Sunken
Value Tab (Tab 2)
Choose Field: CametoSeeYou
Type: Yes/No
Format: Icon
Property to Use: Value
(Tab 3)
Nothing is set.
_____________________________________________________________________________________________________
Sue Mosher [MVP-Outlook] wrote:
What is the code on line 5? The script needs to use the *exact* name of the field. If you have need to build up the body with multiple items, it may be better to build one string, then set the Body property:
Sub Item_Send()
strBody = Item.Body
If Item.UserProperties("property for checkbox1") = True Then
strBody = strBody & vbCrLf & "wants to see you"
End If
If Item.UserProperties("property for checkbox2") = True Then
strBody = strBody & vbCrLf & "please call soon"
End If
'etc
Item.Body = strBody
End Sub
That would also make it easy to throw in a few MsgBox statements to help you troubleshoot how strBody looks after each addition.
Thank you for that.
I followed your script, but only 1 checkbox carried over to the message
field.
I was getting a script debugging screen starting at line 5. I made
sure everything matched the settings on the first checkbox and they do.
Not sure why it would be skipping the remaining 8.
Here are the properties of the good checkbox:
Display Tab
NAME: CametoSeeYou
Caption: Came to See You
Settings: Visible, Enabled, Sunken
Value Tab
Choose Field: CametoSeeYou
Type: Yes/No
Format: Icon
Property to Use: Value
This is the one that transfers over. I used the same settings on the
remainder, but they don't transfer.
Corey
Sue Mosher [MVP-Outlook] wrote:
The page I suggested has all the building blocks you need, but it's not the PropertyChange/CustomPropertyChange event. What you need from that page is the syntax for standard and custom properties -- Item.propertyname and Item.UserProperties("propertname") -- respectively and the syntax for handling unbound controls.
You have to fill in the details, because we can't read your mind or see your form. It sounds like you've identified that your checkbox is bound to an Outlook property, right? Only you know what property that might be. We also don't know what you mean by "the name of the checkbox" -- whether that's supposed to be the name of the bound property or the checkbox caption or the name of the checkbox control.
As for the message body, if you looked in the object browser (F2) in VBA, you'd see there are two properties related to the message body -- Body and HTMLBody. We don't know which one you want to use.
If you prefer If ... End If blocks to Select Case blocks, that's fine. I personally think they're unwieldy if you have a lot of properties whose changes you want to handle.
So, if we make a lot of assumptions about your form that we have no reason to be able to make, a barebones Item_Send procedure to put information related to two bound checkboxes into the body of a message, without caring about its formatting might be:
Sub Item_Send()
If Item.UserProperties("property for checkbox1") = True Then
Item.Body = Item.Body & vbCrLf & "wants to see you"
End If
If Item.UserProperties("property for checkbox2") = True Then
Item.Body = Item.Body & vbCrLf & "please call soon"
End If
End Sub
Of course, if these are unbound checkboxes, then you need to use the other syntax described on that page to get the value from the control.
Sue,
I've read the information you requested. However, in the area of your
Outlook script below there's no code to drop into the following area:
' code to handle a change in MyProp2 goes here
' continue with Case statements for other properties
' whose values you want to monitor
Now, in Excel, (which this is not obviously) you would use an if/then
function. If this cell equals Yes, then give it a number and add it to
something. Then I'd hook it up to a macro. Etc. Etc.
No offense, but in asking again for a straight out code solution
wrather than a "refer to my book" answer, what is the code to make this
following statement happen. "If the check box is marked in an Outlook
form, paste "the name" of the checkbox to the message body text?"
Sue Mosher [MVP-Outlook] wrote:
I'd suggest, then, that you do one of the walkthroughs listed at
http://www.outlookcode.com/d/forms.htm that introduce you to the idea of programming VBScript code for Outlook forms.
Sue,
I'm new to this programming side of Outlook. I went into the Script
editor and was able to pull down the Item Send start and end prompt.
However, from there I'm lost.
Any assistance would be appreciated.
Corey
Sue Mosher [MVP-Outlook] wrote:
You'd need to write code behind the form, probably in the Item_Send event handler to build the Body or HTMLBody property from the fields you're interested in. See
http://www.outlookcode.com/d/propsyntax.htm for basics on Outlook property syntax.
I have a Custom Phone Message form with check boxes.
What I'm trying to do is, upon selection of the text box, to have the
value be pasted into the message body.
Is there a way to do this?
For instance, you check "wants to see you", it'll then paste "wants to
see you" in the message body.
Same for the remaining check boxes.