![]() |
Setting a Category
Hi,
I'm having trouble adding to my code to set a Category by clicking a Checkbox. I'm getting an error on line 8. I think something is wrong with the If-Then clauses, but I researched a bit and it seems right (although probably not). If I remove the SummerEvening and SummerSaturday lines, everything works fine. Here's the code: Function Item_Write() Set myinspector = Item.GetInspector Set test = myInspector.ModifiedFormPages("Availability") Set SummerWeekday = test.Controls("SummerWeekday") Set SummerEvening = test.Controls("SummerEvening") Set SummerSaturday = test.Controls("SummerSaturday") If SummerWeekday.Value = True & Then Item.Categories = Item.Categories & ",SummerWeekday" ElseIf SummerEvening.Value = True & Then Item.Categories = Item.Categories & ",SummerEvening" Else SummerSaturday.Value = True & Then Item.Categories = Item.Categories & ",SummerSaturday" End If End Function Thanks. |
Setting a Category
This is not a valid If ... Then statement:
If SummerWeekday.Value = True & Then the & needs to be removed since there are no strings to join. -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "Scott07" wrote in message ... Hi, I'm having trouble adding to my code to set a Category by clicking a Checkbox. I'm getting an error on line 8. I think something is wrong with the If-Then clauses, but I researched a bit and it seems right (although probably not). If I remove the SummerEvening and SummerSaturday lines, everything works fine. Here's the code: Function Item_Write() Set myinspector = Item.GetInspector Set test = myInspector.ModifiedFormPages("Availability") Set SummerWeekday = test.Controls("SummerWeekday") Set SummerEvening = test.Controls("SummerEvening") Set SummerSaturday = test.Controls("SummerSaturday") If SummerWeekday.Value = True & Then Item.Categories = Item.Categories & ",SummerWeekday" ElseIf SummerEvening.Value = True & Then Item.Categories = Item.Categories & ",SummerEvening" Else SummerSaturday.Value = True & Then Item.Categories = Item.Categories & ",SummerSaturday" End If End Function Thanks. |
Setting a Category
Thanks, that worked. I'm having trouble with the following code, as well.
I've tried varying combinations because I know it's a syntax problem, but none have worked: ElseIf test1.Value & test2.Value = True Then Item.Categories = Item.Categories & ",Test1 & Test2" "Sue Mosher [MVP-Outlook]" wrote: This is not a valid If ... Then statement: If SummerWeekday.Value = True & Then the & needs to be removed since there are no strings to join. -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "Scott07" wrote in message ... Hi, I'm having trouble adding to my code to set a Category by clicking a Checkbox. I'm getting an error on line 8. I think something is wrong with the If-Then clauses, but I researched a bit and it seems right (although probably not). If I remove the SummerEvening and SummerSaturday lines, everything works fine. Here's the code: Function Item_Write() Set myinspector = Item.GetInspector Set test = myInspector.ModifiedFormPages("Availability") Set SummerWeekday = test.Controls("SummerWeekday") Set SummerEvening = test.Controls("SummerEvening") Set SummerSaturday = test.Controls("SummerSaturday") If SummerWeekday.Value = True & Then Item.Categories = Item.Categories & ",SummerWeekday" ElseIf SummerEvening.Value = True & Then Item.Categories = Item.Categories & ",SummerEvening" Else SummerSaturday.Value = True & Then Item.Categories = Item.Categories & ",SummerSaturday" End If End Function Thanks. |
Setting a Category
What's the specific problem? It looks like what this code is supposed to do is check whether two controls both return True and, if they do, append a new category names "Test1 & Test2" to the categories that already exist on 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 "Scott07" wrote in message ... Thanks, that worked. I'm having trouble with the following code, as well. I've tried varying combinations because I know it's a syntax problem, but none have worked: ElseIf test1.Value & test2.Value = True Then Item.Categories = Item.Categories & ",Test1 & Test2" |
Setting a Category
Thanks for the fast reply. If I only check, for example, Test1, the Category
is set properly. Also, if I check Test2, it works properly. However, if I check both and invoke the code below, the Category will remain blank. "Sue Mosher [MVP-Outlook]" wrote: What's the specific problem? It looks like what this code is supposed to do is check whether two controls both return True and, if they do, append a new category names "Test1 & Test2" to the categories that already exist on 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 "Scott07" wrote in message ... Thanks, that worked. I'm having trouble with the following code, as well. I've tried varying combinations because I know it's a syntax problem, but none have worked: ElseIf test1.Value & test2.Value = True Then Item.Categories = Item.Categories & ",Test1 & Test2" |
Setting a Category
Look at the rest of your If ... Then ... End If block. If the criteria have already been met earlier, code execution never gets to the ElseIf statement.
-- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "Scott07" wrote in message ... Thanks for the fast reply. If I only check, for example, Test1, the Category is set properly. Also, if I check Test2, it works properly. However, if I check both and invoke the code below, the Category will remain blank. "Sue Mosher [MVP-Outlook]" wrote: What's the specific problem? It looks like what this code is supposed to do is check whether two controls both return True and, if they do, append a new category names "Test1 & Test2" to the categories that already exist on the item. "Scott07" wrote in message ... Thanks, that worked. I'm having trouble with the following code, as well. I've tried varying combinations because I know it's a syntax problem, but none have worked: ElseIf test1.Value & test2.Value = True Then Item.Categories = Item.Categories & ",Test1 & Test2" |
Setting a Category
Here is some code. I've commented where my code to & two statements together
is. Any help is appreciated. Thanks. Function Item_Write() Set myinspector = Item.GetInspector Set test = myInspector.ModifiedFormPages("Availability") Set Test2 = test.Controls("Test2") Set Test3 = test.Controls("Test3") If Test2.Value = True Then Item.Categories = Item.Categories & ",Test2" ElseIf Test3.Value = True Then Item.Categories = Item.Categories & ",Test3" //////The code below doesn’t work for some reason. It seems to output Test2, but not Test2 & Test3. Is it because of the order of my "if" clauses? If so, how should I restructure them. If not, please let me know what else you believe it could be. ElseIf Test2.Value & Test3.Value = True Then Item.Categories = Item.Categories & ",Test2 & Test3" End If End Function "Sue Mosher [MVP-Outlook]" wrote: Look at the rest of your If ... Then ... End If block. If the criteria have already been met earlier, code execution never gets to the ElseIf statement. -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "Scott07" wrote in message ... Thanks for the fast reply. If I only check, for example, Test1, the Category is set properly. Also, if I check Test2, it works properly. However, if I check both and invoke the code below, the Category will remain blank. "Sue Mosher [MVP-Outlook]" wrote: What's the specific problem? It looks like what this code is supposed to do is check whether two controls both return True and, if they do, append a new category names "Test1 & Test2" to the categories that already exist on the item. "Scott07" wrote in message ... Thanks, that worked. I'm having trouble with the following code, as well. I've tried varying combinations because I know it's a syntax problem, but none have worked: ElseIf test1.Value & test2.Value = True Then Item.Categories = Item.Categories & ",Test1 & Test2" |
Setting a Category
There are two problems with your code. One is with the overall logic. The other is with the second ElseIf statement.
The expression inside an If ... Then statement or an ElseIf ... Then statement must return either True or False. Here's your 2nd ElseIf statement, which does not meet that requirement: ElseIf Test2.Value & Test3.Value = True Then & is a string concatenation operator and has no place in this statement at all. If you want to test whether both values are true, you need two expressions, joined by And: ElseIf (Test2.Value = True) And (Test3.Value = True) Then or, because each of the expressions is redundant, simply: ElseIf Test2.Value And Test3.Value Then Now for the logic problem. If we fix the second ElseIf statement, here's what the logic looks like: If Test2.Value = True Then ' do something ElseIf Test3.Value = True Then ' do something ElseIf (Test2.Value = True) And (Test3.Value = True) Then ' do something End If If either value is True, either the If statement or the first ElseIf statement takes care of the processing. There is no way the 2nd ElseIf statement is ever even tested in those scenarios, because the item would be processed by one of the earlier statements. There are a number of other ways to handle it, including using the expression from the 2nd ElseIf statement in the If statement. I'd recommend that you sketch out the logic with paper and pencil first. -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "Scott07" wrote in message ... Here is some code. I've commented where my code to & two statements together is. Any help is appreciated. Thanks. Function Item_Write() Set myinspector = Item.GetInspector Set test = myInspector.ModifiedFormPages("Availability") Set Test2 = test.Controls("Test2") Set Test3 = test.Controls("Test3") If Test2.Value = True Then Item.Categories = Item.Categories & ",Test2" ElseIf Test3.Value = True Then Item.Categories = Item.Categories & ",Test3" //////The code below doesn’t work for some reason. It seems to output Test2, but not Test2 & Test3. Is it because of the order of my "if" clauses? If so, how should I restructure them. If not, please let me know what else you believe it could be. ElseIf Test2.Value & Test3.Value = True Then Item.Categories = Item.Categories & ",Test2 & Test3" End If End Function "Sue Mosher [MVP-Outlook]" wrote: Look at the rest of your If ... Then ... End If block. If the criteria have already been met earlier, code execution never gets to the ElseIf statement. -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "Scott07" wrote in message ... Thanks for the fast reply. If I only check, for example, Test1, the Category is set properly. Also, if I check Test2, it works properly. However, if I check both and invoke the code below, the Category will remain blank. "Sue Mosher [MVP-Outlook]" wrote: What's the specific problem? It looks like what this code is supposed to do is check whether two controls both return True and, if they do, append a new category names "Test1 & Test2" to the categories that already exist on the item. "Scott07" wrote in message ... Thanks, that worked. I'm having trouble with the following code, as well. I've tried varying combinations because I know it's a syntax problem, but none have worked: ElseIf test1.Value & test2.Value = True Then Item.Categories = Item.Categories & ",Test1 & Test2" |
All times are GMT +1. The time now is 09:18 AM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com