G
gahagan
Hi,
Here was my issue: the listbox_afterupdate() event was firing when
using the mouse to selected more rows in a listbox, but it was NOT
firing when I used the keyboard - SHIFT+UP or SHIFT+DOWN keys.
Specifically, I had a running-total textbox on the bottom right that
performed some math functions on whatever rows were selected (sum of
cost, price, profit, etc.). It wasn't working correctly with the
keyboard events.
I've seen a lot about this issue, without any solution (that I found,
after a rather brief search). But I think I've figured out a
work-around.
I set the lisbox's gotfocus event to set the form's keypreview property
to TRUE, which causes the form to process the keyup/down events before
the control does.
Sub Listbox1_GotFocus()
Me.KeyPreview=True
End Sub
Then, in the form's KeyUp() event, I put the following code:
If KeyCode = vbKeyUp Or KeyCode = vbKeyDown Then
Me.Listbox1_AfterUpdate
End If
I then set the listbox's lostfocus event to set the form's keypreview
property to FALSE.
Sub Listbox1_LostFocus()
Me.KeyPreview=False
End Sub
This was driving me crazy - hopefully this will help someone else out
there with the same problem. So far, it works like a charm.
HTH,
AG
Here was my issue: the listbox_afterupdate() event was firing when
using the mouse to selected more rows in a listbox, but it was NOT
firing when I used the keyboard - SHIFT+UP or SHIFT+DOWN keys.
Specifically, I had a running-total textbox on the bottom right that
performed some math functions on whatever rows were selected (sum of
cost, price, profit, etc.). It wasn't working correctly with the
keyboard events.
I've seen a lot about this issue, without any solution (that I found,
after a rather brief search). But I think I've figured out a
work-around.
I set the lisbox's gotfocus event to set the form's keypreview property
to TRUE, which causes the form to process the keyup/down events before
the control does.
Sub Listbox1_GotFocus()
Me.KeyPreview=True
End Sub
Then, in the form's KeyUp() event, I put the following code:
If KeyCode = vbKeyUp Or KeyCode = vbKeyDown Then
Me.Listbox1_AfterUpdate
End If
I then set the listbox's lostfocus event to set the form's keypreview
property to FALSE.
Sub Listbox1_LostFocus()
Me.KeyPreview=False
End Sub
This was driving me crazy - hopefully this will help someone else out
there with the same problem. So far, it works like a charm.
HTH,
AG