![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
This is a follow up to previous unresolved thread which was getting a bit messy. I have a multi select (extended) unbound list box which has a problem with the keypress event. I'm using the following code in the Click event (which is the last event to run after the KeyPress is triggered). The Process_lst function applies a filter to the main form and returns the position of the correct record in the list box every time for click, keypress or keydown events (so that isn't a problem). The rest of the code shown is only to test what is happening. vIndex = Process_lst With Me!lstCont For i = 0 To .ListCount - 1 If .Selected(i) = True Then MsgBox "Click " & i Next End With For simplicity, assume the list box contains the following values with the relevant list indices shown: Value List Index A1 0 A2 1 B1 2 B2 3 If I press "B", index 2 is selected and the correct filter is applied to the form for B1. If I then press "B" a second time (looking for the next value starting with 'B'), row 3 is initially selected, the correct filter is applied (for B2) but the List resets to index 2 (B1). So at this stage the list and form are showing different records. But the message box shows that the correct index (3) is selected every time. My question is, what is happening after the click event to change the value? And why does it only happen on the second call? Notes: If I remove the Filter event from Process_lst, the behaviour doesn't occur (but obviously I need the filter). The records are not necessarily in alphabetic order as shown, hence the need to search for the next value. There is nothing in the main form which references the list box. The Keypress and KeyDown events only sets a module variable for use by the Process_lst function. There is nothing in the Before or After Update events. Hoping that someone can help. |
#3
| |||
| |||
|
|
On 10/01/2012 02:18:40, Bob Darlington wrote: This is a follow up to previous unresolved thread which was getting a bit messy. I have a multi select (extended) unbound list box which has a problem with the keypress event. I'm using the following code in the Click event (which is the last event to run after the KeyPress is triggered). The Process_lst function applies a filter to the main form and returns the position of the correct record in the list box every time for click, keypress or keydown events (so that isn't a problem). The rest of the code shown is only to test what is happening. vIndex = Process_lst With Me!lstCont For i = 0 To .ListCount - 1 If .Selected(i) = True Then MsgBox "Click "& i Next End With For simplicity, assume the list box contains the following values with the relevant list indices shown: Value List Index A1 0 A2 1 B1 2 B2 3 If I press "B", index 2 is selected and the correct filter is applied to the form for B1. If I then press "B" a second time (looking for the next value starting with 'B'), row 3 is initially selected, the correct filter is applied (for B2) but the List resets to index 2 (B1). So at this stage the list and form are showing different records. But the message box shows that the correct index (3) is selected every time. My question is, what is happening after the click event to change the value? And why does it only happen on the second call? Notes: If I remove the Filter event from Process_lst, the behaviour doesn't occur (but obviously I need the filter). The records are not necessarily in alphabetic order as shown, hence the need to search for the next value. There is nothing in the main form which references the list box. The Keypress and KeyDown events only sets a module variable for use by the Process_lst function. There is nothing in the Before or After Update events. Hoping that someone can help. Don't know why you have the problem, but I always reset a ListBox or ComboBox after the CurrentEvent on a form to the main key on the form. ie Private Sub Form_Current() lstcont = Me!ID end sub That way they always stay in sync. Phil Phil Thanks Phil, |
![]() |
| Thread Tools | |
| Display Modes | |
| |