M
MikeC
I'm developing an Access 2002 application on a Windows XP machine. I have
two unbound listboxes, "lstFY" and "lstAppCd", on the same unbound form.
(Some of the property settings are shown at the bottom of this post.)
The lstFY listbox has one event procedure in its AfterUpdate event. The
procedure requeries a second listbox, lstAppCd and 4 combo boxes. After
lstAppCd is requeried, all items in lstAppCd are selected using another sub
procedure (below).
About 98% of the time the code works fine. However, during testing I
discovered that when I use my mouse to change the selected value in lstFY
and then change the value back to what it was previously and then click on
the same selection a 2nd or 3rd time, all items in lstAppCd are deselected.
See below example. Very strange. I also found that the problem goes away
if I comment-out the line that requeries the lstAppCd listbox. This is an
important clue, but I don't understand the underlying problem.
3-Step Example:
1) Click on 2005 in lstFY listbox. - lstAppCd list box is requeried and all
items are selected.
2) Click on 2006 in lstFY listbox. - lstAppCd list box is requeried and all
items are selected.
3) Click on 2006 again in lstFY listbox. - lstAppCd list box is requeried
and all NONE of the items are selected. I have already verified via
Debug.Print that the "Selected" property for each item is literally set to
*False* despite the fact that I specified "True," not "False"!!! Normally,
the value is set to True, but not in the above scenario.
Has anyone experienced this type of problem with a listbox or know how to
solve the problem?
The VBA code is shown below:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Private Sub lstFY_AfterUpdate()
'This procedure requeries the controls whenever the fiscal year
'selected in the lstFY listbox changes and selects all items in
'the lstAppCd listbox.
On Error GoTo ERR_HANDLER
With Me
'Requery the lstAppCd list box.
!lstAppCd.Requery
'Select all items in the lstAppCd list box.
SelectListBoxItems !lstAppCd
'Requery the comparison period combo boxes.
!cmbPos1.Requery
!cmbPos2.Requery
!cmbPos3.Requery
!cmbPos4.Requery
End With
EXIT_PROCEDURE:
Exit Sub
ERR_HANDLER:
If Err.Number <> 2501 Then
ErrorHandler Err.Number, Err.Description, "lstFY_AfterUpdate",
Me.Name
End If
Resume EXIT_PROCEDURE
End Sub
Public Sub SelectListBoxItems(lstBox As ListBox)
On Error GoTo ERR_HANDLER
'This procedure selects all items in a specified list box.
'
'This code is part of a standard code module.
Dim lngListCount As Long
With lstBox
For lngListCount = 0 To .ListCount - 1
.Selected(lngListCount) = True
Debug.Print .Selected(lngListCount)
Next lngListCount
End With
EXIT_PROCEDURE:
On Error Resume Next
Set lstBox = Nothing
Exit Sub
ERR_HANDLER:
If Err.Number <> 2501 Then
ErrorHandler Err.Number, Err.Description, "SelectListBoxItems",
mconModuleName
End If
Resume EXIT_PROCEDURE
End Sub
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Some lstFY Listbox Properties:
ColumnCount = 1
RowSource = qryFiscalYearLookup
Enabled = Yes
Multiselect = None
ColumnHeads = No
Some lstAppCd Listbox Properties:
ColumnCount = 4
RowSource = qryAppCodeLookup
Enabled = Yes
Multiselect = Extended
ColumnHeads = No
The application has also been decompiled and recompiled, but the problem
remains.
two unbound listboxes, "lstFY" and "lstAppCd", on the same unbound form.
(Some of the property settings are shown at the bottom of this post.)
The lstFY listbox has one event procedure in its AfterUpdate event. The
procedure requeries a second listbox, lstAppCd and 4 combo boxes. After
lstAppCd is requeried, all items in lstAppCd are selected using another sub
procedure (below).
About 98% of the time the code works fine. However, during testing I
discovered that when I use my mouse to change the selected value in lstFY
and then change the value back to what it was previously and then click on
the same selection a 2nd or 3rd time, all items in lstAppCd are deselected.
See below example. Very strange. I also found that the problem goes away
if I comment-out the line that requeries the lstAppCd listbox. This is an
important clue, but I don't understand the underlying problem.
3-Step Example:
1) Click on 2005 in lstFY listbox. - lstAppCd list box is requeried and all
items are selected.
2) Click on 2006 in lstFY listbox. - lstAppCd list box is requeried and all
items are selected.
3) Click on 2006 again in lstFY listbox. - lstAppCd list box is requeried
and all NONE of the items are selected. I have already verified via
Debug.Print that the "Selected" property for each item is literally set to
*False* despite the fact that I specified "True," not "False"!!! Normally,
the value is set to True, but not in the above scenario.
Has anyone experienced this type of problem with a listbox or know how to
solve the problem?
The VBA code is shown below:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Private Sub lstFY_AfterUpdate()
'This procedure requeries the controls whenever the fiscal year
'selected in the lstFY listbox changes and selects all items in
'the lstAppCd listbox.
On Error GoTo ERR_HANDLER
With Me
'Requery the lstAppCd list box.
!lstAppCd.Requery
'Select all items in the lstAppCd list box.
SelectListBoxItems !lstAppCd
'Requery the comparison period combo boxes.
!cmbPos1.Requery
!cmbPos2.Requery
!cmbPos3.Requery
!cmbPos4.Requery
End With
EXIT_PROCEDURE:
Exit Sub
ERR_HANDLER:
If Err.Number <> 2501 Then
ErrorHandler Err.Number, Err.Description, "lstFY_AfterUpdate",
Me.Name
End If
Resume EXIT_PROCEDURE
End Sub
Public Sub SelectListBoxItems(lstBox As ListBox)
On Error GoTo ERR_HANDLER
'This procedure selects all items in a specified list box.
'
'This code is part of a standard code module.
Dim lngListCount As Long
With lstBox
For lngListCount = 0 To .ListCount - 1
.Selected(lngListCount) = True
Debug.Print .Selected(lngListCount)
Next lngListCount
End With
EXIT_PROCEDURE:
On Error Resume Next
Set lstBox = Nothing
Exit Sub
ERR_HANDLER:
If Err.Number <> 2501 Then
ErrorHandler Err.Number, Err.Description, "SelectListBoxItems",
mconModuleName
End If
Resume EXIT_PROCEDURE
End Sub
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Some lstFY Listbox Properties:
ColumnCount = 1
RowSource = qryFiscalYearLookup
Enabled = Yes
Multiselect = None
ColumnHeads = No
Some lstAppCd Listbox Properties:
ColumnCount = 4
RowSource = qryAppCodeLookup
Enabled = Yes
Multiselect = Extended
ColumnHeads = No
The application has also been decompiled and recompiled, but the problem
remains.