Custom Form - Checkboxes

S

Scott07

Hi,

I'm attempting to create a custom contact form with 3 checkboxes that, when
checked, will add the form to a category (e.g. where Business, Competition,
Favorites, etc. are shown under "Available Categories"). For example, if the
checkboxes were named test1, test2, and test3; after those three were
checked, I'd like the form to be automatically classified under the
"Business" category.

Any help is appreciated.

Thanks.
 
S

Sue Mosher [MVP-Outlook]

You'll need to do this in code behind the form, in the Item_Write event handler, adding Business as a category if your criteria are met. How you get the values of the check boxes depends on whether the boxes are bound or unbound; see http://www.outlookcode.com/article.aspx?ID=38

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/article.aspx?id=54
 
S

Scott07

I visited your link and noticed an article outlining how to use a checkbox to
show and hide a frame. I've removed the references to the frame since I
won't be needing that, but I don't know where to go with the Item_Write part
and how to make the act of checking the checkbox add it to the "Business"
category. This is for an unbound checkbox, by the way:

Sub CheckBox1_Click()
Set myinspector = Item.GetInspector
Set myPage1 = myInspector.ModifiedFormPages("Message")
Set Checkbox1 = myPage1.Controls("CheckBox1")
End Sub

Thanks.
 
S

Sue Mosher [MVP-Outlook]

The sample you saw showed how to get the value of an unbound check box with its Value property. You need just three more pieces to write all the code. Use the code window's Script | Event Handler to insert the Item_Write event handler. In that procedure, you'll want to test the value returned by the check box, and if it's True, append to the item's Categories property:

If CheckBox1.Value = True Then
Item.Categories = Item.Categories & ",Business"
End If


--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/article.aspx?id=54
 
S

Scott07

So, something like this (could use some syntax help please):

Function Item_Write()
If CheckBox1.Value = True Then
Item.Categories = Item.Categories & ",Business"
End If
End Function

I realize you mentioned I needed this somewhere, but am not sure how to
integrate the code together:

Sub CheckBox1_Click()
Set myinspector = Item.GetInspector
Set myPage1 = myInspector.ModifiedFormPages("Message")
Set Checkbox1 = myPage1.Controls("CheckBox1")
End Sub

Thanks.
 
S

Sue Mosher [MVP-Outlook]

The three statements in the second procedure are the ones you need to use to return the check box as an object. You need to do that before you can get its value. In other words, put those 3 statements before the first statement in Item_Write.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/article.aspx?id=54
 
S

Scott07

I've placed the code, as follows, but am not getting any results. To test,
I've created a "Categories" box on my form to see if it is getting set to
"Business" when the checkbox is clicked. However, nothing is happening. Any
ideas why?

Thank you for your patience.

Sub CheckBox1_Click()
Set myinspector = Item.GetInspector
Set myPage1 = myInspector.ModifiedFormPages("Message")
Set Checkbox1 = myPage1.Controls("CheckBox1")
End Sub

Function Item_Write()
If CheckBox1.Value = True Then
Item.Categories = Item.Categories & ",Business"
End If
End Function
 
S

Sue Mosher [MVP-Outlook]

I think you misunderstood my earlier post. It explained how to modify the Item_Write procedure so that it contains the three statements required to instantiate a CheckBox1 object so that you can return its value. You do not need a CheckBox1_Click procedure at all.

Also, don't forget that you need to publish the form with the "send form definition with item" box unchecked. Code runs only on published, non-oneoff forms.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
S

Scott07

Oh, I see. The Click procedure was somewhat confusing to me anyways. So,
basically, now I have the following code:

Function Item_Write()
If CheckBox1.Value = True Then
Item.Categories = Item.Categories & ",Business"
End If
End Function

Is there any way to test that this is working properly? I placed an unbound
"Categories" box on my form to see if it would be classified as "Business"
after clicking on the checkbox, but nothing is happening.

Thanks.
 
S

Sue Mosher [MVP-Outlook]

That's still not going to work. Here are my original instructions again:

CheckBox1 by itself is meaningless to Outlook form code. You need the other three statements from the Click event handler that you've now discarded to instantiate a CheckBox1 value. Those three statements need to go into the Item_Write procedure, before the CheckBox1.Value statement.

An "unbound 'Categories' box" won't do anything. The only place that you'd see a change is in the actual Categories property, and only if you follow the above instructions. Furthermore, the only event handler is Item_Write. It runs when the user saves the item.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
S

Scott07

I can't test this currently, but are you suggesting the following code is
correct? I misunderstood your instructions, in that, I thought the object
declaration took place before the CheckBox1.Value code:

Function Item_Write()
Set myinspector = Item.GetInspector
Set myPage1 = myInspector.ModifiedFormPages("Message")
Set Checkbox1 = myPage1.Controls("CheckBox1")

If CheckBox1.Value = True Then
Item.Categories = Item.Categories & ",Business"
End If
End Function

Also, can you please let me know what the setting of "myPage1" accomplishes?
Is that the name of the page of my form?

Thank you.
 
S

Sue Mosher [MVP-Outlook]

Yes, that's the correct code. myPage1 is an object representing the page where the CheckBox1 control resides. The name of the page is the argument passed to ModifiedFormPages, i.e. "Message." Of course if your page and control have different names, you'd need to adjust the code accordingly.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
S

Scott07

Thanks. So, here is the code that I have right now:

Function Item_Write()
Set myinspector = Item.GetInspector
Set General = myInspector.ModifiedFormPages("Message")
Set Checkbox1 = General.Controls("CheckBox1")

If CheckBox1.Value = True Then
Item.Categories = Item.Categories & ",Business"
End If
End Function

For testing purposes, I am using the "General" page as the area to set the
"Category" as "Business." However, nothing is happening when I run the form
and click the checkbox. Anything else I'm missing?

Thanks.
 
S

Sue Mosher [MVP-Outlook]

For testing purposes, I am using the "General" page as the area to set the
"Category" as "Business."

I don't know what you mean by "the area to set ..."
However, nothing is happening when I run the form
and click the checkbox.

That's normal and expected, since the code is in the event handler for the Write event. Nothing will happen until the item is saved.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
H

Hollis Paul

Set General = myInspector.ModifiedFormPages("Message")
OK. You now have the collection of pages as an object. You need to
set an object to a specific page, then set the checkbox. You see the
checkbox now because the General page is the default of the collection,
but that is really sloppy programming.
 
S

Scott07

Hi, Sue,

To clarify, I meant that I was checking the functionality of my Checkbox by
viewing the General page, where the Categories are shown (to see if it was
getting set to "Business"). After attempting to save the form, as you
described, I am getting the following error:

Object required: 'General'
Line No: 4

Here's my code, once again. I'm not sure why there's a problem, as I'm
using the General page and I believe I've renamed it appropriately:

Function Item_Write()
Set myinspector = Item.GetInspector
Set General = myInspector.ModifiedFormPages("Message")
Set Checkbox1 = General.Controls("CheckBox1")

If CheckBox1.Value = True Then
Item.Categories = Item.Categories & ",Business"
End If
End Function

Thanks.
 
S

Sue Mosher [MVP-Outlook]

If the page is named General, then you won't get anything from this statement:

Set General = myInspector.ModifiedFormPages("Message")

From my earlier post: The name of the page is the argument passed to ModifiedFormPages, i.e. "Message." Of course if your page and control have different names, you'd need to adjust the code accordingly.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
S

Scott07

If I'm understanding correctly, "Message" is the name of the page? Is
General the object?

Thanks.
 
S

Scott07

So, here's my code. I'm not getting an error anymore, but for some reason,
I'm getting the date and time filled into the Categories box as soon as the
form is opened (6/1/2007 8:00:00AM). Any ideas why?

Thanks.

Function Item_Write()
Set myinspector = Item.GetInspector
Set test = myInspector.ModifiedFormPages("General")
Set Checkbox1 = test.Controls("CheckBox1")

If CheckBox1.Value = True Then
Item.Categories = Item.Categories & ",Business"
End If
End Function
 

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