MS Office Forum / Outlook / Programming Forms / June 2007
Custom Form - Checkboxes
|
|
Thread rating:  |
Scott07 - 07 Jun 2007 15:57 GMT 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.
Sue Mosher [MVP-Outlook] - 07 Jun 2007 16:15 GMT 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
 Signature Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/article.aspx?id=54
> Hi, > [quoted text clipped - 8 lines] > > Thanks. Scott07 - 08 Jun 2007 16:49 GMT 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.
> 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 > [quoted text clipped - 10 lines] > > > > Thanks. Sue Mosher [MVP-Outlook] - 08 Jun 2007 17:00 GMT 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
 Signature Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/article.aspx?id=54
>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 [quoted text clipped - 24 lines] >> > >> > Thanks. Scott07 - 12 Jun 2007 16:51 GMT 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.
Sue Mosher [MVP-Outlook] - 12 Jun 2007 18:10 GMT 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.
 Signature Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/article.aspx?id=54
> So, something like this (could use some syntax help please): > [quoted text clipped - 14 lines] > > Thanks. Scott07 - 13 Jun 2007 16:18 GMT 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
> 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. > > So, something like this (could use some syntax help please): [quoted text clipped - 15 lines] > > > > Thanks. Sue Mosher [MVP-Outlook] - 13 Jun 2007 16:35 GMT 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.
 Signature Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54
> 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 [quoted text clipped - 16 lines] > >> 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.
>> > So, something like this (could use some syntax help please): >> > [quoted text clipped - 14 lines] >> > >> > Thanks. Scott07 - 14 Jun 2007 14:53 GMT 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.
> 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. > [quoted text clipped - 39 lines] > >> > > >> > Thanks. Sue Mosher [MVP-Outlook] - 14 Jun 2007 15:02 GMT That's still not going to work. Here are my original instructions again:
>> >> 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. 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.
 Signature Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54
> Oh, I see. The Click procedure was somewhat confusing to me anyways. So, > basically, now I have the following code: [quoted text clipped - 14 lines] >> >> 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.
>> > 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 [quoted text clipped - 35 lines] >> >> > >> >> > Thanks. Scott07 - 17 Jun 2007 17:56 GMT 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.
> That's still not going to work. Here are my original instructions again: > [quoted text clipped - 61 lines] > >> >> > > >> >> > Thanks. Sue Mosher [MVP-Outlook] - 17 Jun 2007 19:27 GMT 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.
 Signature Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54
>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 [quoted text clipped - 81 lines] >> >> >> > >> >> >> > Thanks. Scott07 - 18 Jun 2007 14:10 GMT 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.
> 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. > [quoted text clipped - 83 lines] > >> >> >> > > >> >> >> > Thanks. Sue Mosher [MVP-Outlook] - 18 Jun 2007 15:52 GMT > 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.
 Signature Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54
> Thanks. So, here is the code that I have right now: > [quoted text clipped - 101 lines] >> >> >> >> > >> >> >> >> > Thanks. Scott07 - 19 Jun 2007 13:38 GMT 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.
> > For testing purposes, I am using the "General" page as the area to set the > > "Category" as "Business." [quoted text clipped - 111 lines] > >> >> >> >> > > >> >> >> >> > Thanks. Sue Mosher [MVP-Outlook] - 19 Jun 2007 13:40 GMT 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.
 Signature Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54
> Hi, Sue, > [quoted text clipped - 136 lines] >> >> >> >> >> > >> >> >> >> >> > Thanks. Scott07 - 21 Jun 2007 16:02 GMT If I'm understanding correctly, "Message" is the name of the page? Is General the object?
Thanks.
> If the page is named General, then you won't get anything from this statement: > [quoted text clipped - 142 lines] > >> >> >> >> >> > > >> >> >> >> >> > Thanks. Sue Mosher [MVP-Outlook] - 21 Jun 2007 20:00 GMT Yes, exactly. You can tell by the quotation marks around it that "Message" is a string literal.
 Signature Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54
> If I'm understanding correctly, "Message" is the name of the page? Is > General the object? [quoted text clipped - 147 lines] >> >> >> >> >> >> > >> >> >> >> >> >> > Thanks. Scott07 - 22 Jun 2007 16:41 GMT 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
> Yes, exactly. You can tell by the quotation marks around it that "Message" is a string literal. > [quoted text clipped - 149 lines] > >> >> >> >> >> >> > > >> >> >> >> >> >> > Thanks. Sue Mosher [MVP-Outlook] - 22 Jun 2007 16:58 GMT Do you also have a formula set for Categories? If so, remove it.
 Signature Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54
> 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 [quoted text clipped - 13 lines] > >> Yes, exactly. You can tell by the quotation marks around it that "Message" is a string literal.
>> > If I'm understanding correctly, "Message" is the name of the page? Is >> > General the object? [quoted text clipped - 147 lines] >> >> >> >> >> >> >> > >> >> >> >> >> >> >> > Thanks. Scott07 - 25 Jun 2007 15:06 GMT I got the Categories/date-time problem resolved by creating a new form (I couldn't find any formulas set for Categories, so I used this method). However, upon running my form, I'm getting an error 'Object required: 'test" on line 4. I believe that "test" is the object and it's being passed to the next line, but there's something I'm not noticing.
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
> Do you also have a formula set for Categories? If so, remove it. > > So, here's my code. I'm not getting an error anymore, but for some reason, [quoted text clipped - 166 lines] > >> >> >> >> >> >> >> > > >> >> >> >> >> >> >> > Thanks. Sue Mosher [MVP-Outlook] - 25 Jun 2007 15:42 GMT The error suggests that there is no customized page with a display name of "General."
 Signature Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54
> However, upon running my form, I'm getting an error 'Object required: 'test" > on line 4. I believe that "test" is the object and it's being passed to the [quoted text clipped - 11 lines] > End If > End Function Hollis Paul - 18 Jun 2007 16:41 GMT > 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.
-- Hollis Paul Mukilteo, WA USA
|
|
|