Grid Control Rows Not Displaying Selected State Correctly
this is very weird (and urgent).
when i select rows in a grid control on a form, using access vba, some rows behave exactly the opposite of how they're supposed to behave-- they APPEAR unselected when i select them, and selected when i unselect them. However, when i check their Selected property with VBA they return the expected value.
video:
youtu.be/Ae0adXdmT48
i repeatedly requery the listbox while the form it's on is hidden (MyForm.Visible=False). It seems that the more times i requery, the worse the problem gets.
Code:
' requery
oListBox.Requery
Then i select ALL items in the list box by looping through them.
Code:
Sub Select_AllListItems(oListBox As ListBox)
' select all items in list
DoCmd.Echo False
oListBox.Visible = False
Dim lngRow As Long
For lngRow = 0 To oListBox.ListCount - 1
oListBox.Selected(lngRow) = True
Next
' jump to top
oListBox.Selected(0) = True
DoCmd.Echo True
oListBox.Visible = True
End Sub
This problem seems unrelated to the number of times i run the above procedure. It seems only related to multiple requeries. At first, it does not happen. Then with repeated requeries (while the form is hidden), the problem gets progressively worse.
maybe i'm accessing the form in the wrong way, creating multiple instances or something. But i'm not using the "Form_" syntax anyplace.
also, this listbox query contains a vba function which is in the code-behind of another form.
help!
note, i may post this question on other MS Access forums, so plz only answer in one place. thx!
Possibly Solved. Possible Microsoft Access Bug.
i think i solved this.
Problem: when VBA selects all rows in a listbox every time the listbox is requeried, selection behavior gets wonky: some selected rows do not appear selected.
Demo of problem:
https://drive.google.com/file/d/0B8F...lh4SDcyUk11bWc
instructions:
https://docs.google.com/document/d/1...avxFRMocvOZ1RY
the fix is to UNselect all rows in the target table before requerying it.
Produced wonky selection behavior:
1. ListBox Where condition changes
2. Requery ListBox
3. Select All ListBox Rows
4. Repeat
Fixed wonky selection behavior:
1. ListBox Where condition changes
2. UNselect All ListBox Rows
3. Requery ListBox
4. Select All ListBox Rows
5. Repeat
see debug-fix
https://drive.google.com/file/d/0B8F...3FucTZ0Qm15ekE
i think this might be a Microsoft Access Bug, because the behavior (selected rows appearing unselected) is abnormal.
i'll mark this thread solved, after anybody confirms my fix works.
thx!