Code Unbound Control in Outlook Form

Senniger1
Senniger1 used Ask the Experts™
on
In Outlook 2003 I have an Unbound Control name "chkYes" which is a CheckBox.  The page in the form is named "Credit".

I'm trying to code the form so when I click the checkbox "chkYes" to put a check in the box, once I send the form, the box will be checked for the recipient.

Below is what I have so far.  I realize I haven't set the value of the checkbox to "True", but everything I attempted didn't work so I left it off this.


Set objPage = Item.GetInspector.ModifiedFormPages("Credit")
Set objControl = objPage.Controls("chkYes")
MyValue = objControl.Value

Any assistance would be greatly appreciated.

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010
Commented:
Hi, Senniger1.

Controls do not store values.  They display and enable you to change them, but the value of a control is lost as soon as the form is closed.  Values have to be saved in a property if you want them to persist.  That means binding the control to a property or setting it through code.  The property can be a built-in one or a user-defined one.  

Author

Commented:
Yes, that is correct.  Data entered in an unbound control is discarded unless you include code behind the form to save it to an Outlook property.  This is the code I'm trying to write which I need help.

The reason I'm not using a built-in property is because then the following code won't work.

'cmdInsertFile begin
    Dim objInsp       
    Dim colCB
    Dim objCBB
    On Error Resume Next
    Set objInsp = Item.GetInspector
    Set colCB = objInsp.CommandBars
    Set objCBB = colCB.FindControl(, 1079)
    If Not objCBB Is Nothing Then
        objCBB.Execute
    End If
    Set objCBB = Nothing
    Set colCB = Nothing
    Set objInsp = Nothing
'cmdInsertFile end

What I'm trying to accomplish is this.  I want a checkbox on the form.  When a user clicks on the checkbox, a message pops up telling them to attach a file.  Then the "cmdInsertFile begin" runs and opens the window so they can browse to the file.  Then the send the email.  When the recipient opens the email (which is a form) they should see the back checked.
Top Expert 2010

Commented:
Sorry, I'm confused.  Are you saying that you don't want to retain the fact that the box was checked, that you're using it to trigger an action like clicking a button?  If so, then I don't understand what you meant in the original question when you said "once I send the form, the box will be checked for the recipient."  If not, then I don't understand what checking the box has to do with the code you posted in your reply.  Please help me understand.
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
I'm sorry for my typos which I'm sure was confusing.  Let me also say I'm very new with this and only know a little.

I'm saying I do want to retain the fact that the box was checked and I am using the box to trigger an action like clicking a button

Once I send the form, the box needs to be checked for the recipient.
Top Expert 2010

Commented:
Got it.  Are you expecting the action to be triggered at the sender or recipient's end?

Author

Commented:
The sender.  Basically when they click the check box, they're prompted to attach a file (so they don't forget.

On the recipient side, they box is just check so when they print it, they'll be a record of the choices selected.l
Top Expert 2010

Commented:
Ok, so you're saying that when you check the box it will not run the code in your post #33946901?

Author

Commented:
Yes, that is correct.  The code will only work if the checkbox is unbound.  But if the checkbox is unbound, then data is discarded when the for is sent.
Top Expert 2010

Commented:
For unbound controls you have to provide the code that stores the control value in the form property and sets the value of the control when the form first loads.  For the latter you trap the Item_Open event, get the page the control is on, get the control, and set the initial value equal to the value of the form property.  The code also must trap the control's Click event in order to get the new value of the control and store it in the form property.  This is also where your code goes.

Here's an example.  You need to change the form, control, and form property names.
Sub Item_Open()
    Set objPage = Item.GetInspector.ModifiedFormPages("P.2")
    Set objControl = objPage.Controls("CheckBox1")
    objControl.Value = Item.UserProperties.Item("David1").Value
    Set objPage = Nothing
    Set objControl = Nothing
End Sub

Sub Checkbox1_Click()
    Item.UserProperties.Item("David1").Value = (Not Item.UserProperties.Item("David1").Value)
    If Item.UserProperties.Item("David1").Value Then
        'Your code goes here'
    End If
End Sub

Open in new window

Author

Commented:
Thank you for your help so far.  In the If, Then statement, which part of the codes validates the checkbox is check (or equial to True)?
Top Expert 2010
Commented:
The code doesn't check the value of the checkbox.  It stores the value of the checkbox in the user property and checks its value.  This is the code that checks the value of the user property.

Item.UserProperties.Item("David1").Value

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial