Problem with Event firing of Function MyListbox_Click()

J

John E.

Please refer to below listed code to answer this question.
I originally used the exact same code contained in Function
lstLicense_Click() as a Sub procedure which was called from my Function
Item_Write() event. When I used it that way the code worked, however, I saw
inconsitent behaviour due to the resulting listbox check-box values usually
but not always saving and showing on re-opening. Because of this
intermittent behaviour, I therefore decided to execute the code when fired by
the event Function lstLicense_Click() as shown rather than being called as a
sub by the Function Item_Write() event. I cannot get the event to fire when
I check one of the checkboxes in the listbox. I noticed on page 385 of Sue
Mosher's book that for a listbox event to fire you must click on the list
item...not in the blank area in the list box..in order for the Click event to
fire. I have tried both ways of clicking the checkbox and still can't get
the event to fire. Can you advise me what I am doing wrong in this code or
if I should take a different approach to get this code to execute when a
listbox is checked????
'-----------------------------------------------------------------------------------------------
Private Function lstLicense_Click()
'Whenever a new checkbox in the listbox is selected by the user this
procedure executes to update the resulting checkbox selection states into a
data store that is stored in the keywords of a ControlButton for persistence.
Dim MyControl
Dim m_strLicenseList
Dim j
Set m_objPage = Item.GetInspector.ModifiedFormPages("General")
Set m_lstLicenseList = m_objPage.Controls("lstLicense")
Set MyControl = m_objPage.Controls("tboxLicense")
m_strLicenseList = ""
' Use Keyword technique from MSDN KB Artilce ID 291117 to store LicenseList
selected data
For j = 0 to (m_lstLicenseList.ListCount - 1) 'Save checkbox status to
data store
If m_lstLicenseList.Selected(j) = True Then
m_strLicenseList = m_strLicenseList & "," &
m_lstLicenseList.List(j)
Call cbUpdateLists_Click(m_strLicenseList,"cbUpdateLists","tboxLicense")
End If
Next
MsgBox "Shows the license list after lstLicense_Click as " & MyControl.Value
Set MyControl = Nothing
End Function
'------------------------------------------------------------------------------------------
Private Sub cbUpdateLists_Click(strList,controlbutton_name,tbox_name)
'Uses Keyword technique from MSDN KB Article ID 291117 to store selected
data in ListBox for
'persistence.
Dim MyPage
Dim MyControl1
Dim MyControl2
Set MyPage = Item.GetInspector.ModifiedFormPages("General")
Set MyControl1 = MyPage.Controls(controlbutton_name)
'MyControl1.Backcolor = 255 'Set control button RED when made visible
during testing
Set MyControl2 = MyPage.Controls(tbox_name)
If strList = MyControl2.Value Then
MyControl2 = ""
End If
MyControl2.Value = strList
MsgBox "Current MyControl2.Value in cbUpdateList_Click is " &
MyControl2.Value 'Shows current List
Set MyPage = Nothing
Set MyControl1 = Nothing
Set MyControl2 = Nothing
End Sub
'------------------------------------------------------------------------------------------
 
S

Sue Mosher [MVP-Outlook]

A Click event will fire on a list box only if

a) the list box is not bound to an Outlook property, and
b) the list box is a single select list, not a multi-select list.

Given your scenario, information about the user's selections should be saved using the Item_Write event handler -- and should be saved to an Outlook property, not a control value.

Note, however, that if the item is not "dirty," Item_Write will not fire. Selecting items in an unbound list box does not dirty the item.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
J

John E.

Ok, so since I have to use a multi-select list in my application, I
understand I can't use the Click event on my list box to execute code after
selecting one of the items in the list. This pushes me back to placing the
code in a Sub and calling it from the Item_Write event handler as I was
originaly doing and as you suggest here. This raises following issues:

1) As you can see from my current code in my original posting in this
thread, the user's listbox selections are being "filtered" via a
controlbutton named 'cbUpdateLists', to the keword field of a textbox named
'tboxLicense'. This is per techniqes described in
http://support.microsoft.com/default.aspx/kb/291117/en-us which you
previously referred me to. My code is attempting following scenario:
a) When a listbox is checked by user, the newly checked list item as
contained in variable 'strlist' is passed via the argument 'tbox_name' to the
controlbutton click procedure. This in effect is a 'programatic "click" of
the button which I make invisible to my form.
b) The newly checked list item contained in 'strlist' is then added to the
keyword field named 'tboxLicense' by the programatic "click" of the
controlbutton via the call of the Sub and the execution of the code in the
controlbutton click procedure.
I am doing all this , per your previous suggestions in answer to previous
questions, so I can make the list box settings persistent on next re-open of
the item and still have the keyword field appear in proper groupings in
custom views/reports. Your most recent comment that the selections should
be saved to an Outlook property and not a control value therefore confuses
me. I in fact am NOT saving them to a control value but rather to a textbox
keyword field via the filtering thru the control. Is this OK??? If not,
how would I save them to an Outlook property instead of filtering them via
the control to the textbox keyword field and still make them persistent?

2) I also am a little confused about your comment that the Item_Write will
not fire unless an item is "dirty"...does "dirty" in my case mean that one of
the listboxes has been checked thus making the item dirty? If it won't fire
unless dirty, does this mean that if I make the listbox selections and then
Save/Close the item using the Write_Item event handler and Item_Close handler
that the Sub that is called by Item_Write will not actually save the
selections thru my filtering procedure to the keyword field?
 
S

Sue Mosher [MVP-Outlook]

1) > in fact am NOT saving them to a control value but rather to a textbox
keyword field via the filtering thru the control. Is this OK???

If the control is bound to a property, then setting the control's value will set the underlying property's value.

My personal preference, FWIW, is to use a text property, rather than a keywords property, to store selections from an unbound multi-select list box as a delimited list. IIRC, my sample form at http://www.outlookcode.com/files/FormControlsDemo.zip uses this technique.
a) When a listbox is checked by user, the newly checked list item as
contained in variable 'strlist' is passed via the argument 'tbox_name' to the
controlbutton click procedure. This in effect is a 'programatic "click" of
the button which I make invisible to my form.

This is a problem because no event fires when the user checks another item in a multi-select list box. Instead of building the list selection-by-selection, you'll need to build it in one fell swoop in Item_Write.

2) An item becomes "dirty" (i.e. the item.Saved = False) if a property on an item changes. If the only thing the user does is change values in an unbound control, then no property on the item has changed, Item.Saved = True, and Item_Writte will not fire.

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

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


John E. said:
Ok, so since I have to use a multi-select list in my application, I
understand I can't use the Click event on my list box to execute code after
selecting one of the items in the list. This pushes me back to placing the
code in a Sub and calling it from the Item_Write event handler as I was
originaly doing and as you suggest here. This raises following issues:

1) As you can see from my current code in my original posting in this
thread, the user's listbox selections are being "filtered" via a
controlbutton named 'cbUpdateLists', to the keword field of a textbox named
'tboxLicense'. This is per techniqes described in
http://support.microsoft.com/default.aspx/kb/291117/en-us which you
previously referred me to. My code is attempting following scenario:
a) When a listbox is checked by user, the newly checked list item as
contained in variable 'strlist' is passed via the argument 'tbox_name' to the
controlbutton click procedure. This in effect is a 'programatic "click" of
the button which I make invisible to my form.
b) The newly checked list item contained in 'strlist' is then added to the
keyword field named 'tboxLicense' by the programatic "click" of the
controlbutton via the call of the Sub and the execution of the code in the
controlbutton click procedure.
I am doing all this , per your previous suggestions in answer to previous
questions, so I can make the list box settings persistent on next re-open of
the item and still have the keyword field appear in proper groupings in
custom views/reports. Your most recent comment that the selections should
be saved to an Outlook property and not a control value therefore confuses
me. I in fact am NOT saving them to a control value but rather to a textbox
keyword field via the filtering thru the control. Is this OK??? If not,
how would I save them to an Outlook property instead of filtering them via
the control to the textbox keyword field and still make them persistent?

2) I also am a little confused about your comment that the Item_Write will
not fire unless an item is "dirty"...does "dirty" in my case mean that one of
the listboxes has been checked thus making the item dirty? If it won't fire
unless dirty, does this mean that if I make the listbox selections and then
Save/Close the item using the Write_Item event handler and Item_Close handler
that the Sub that is called by Item_Write will not actually save the
selections thru my filtering procedure to the keyword field?
 

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