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
'------------------------------------------------------------------------------------------
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
'------------------------------------------------------------------------------------------