![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
The following is a follow up to a previous post. I'm using Access 2010 with a form containing a multi select list box. The code I'm using for the KeyPress event in the list box, calls the after update event for the same control which applies a filter to the form. THe KeyPress event tries to match a record starting with the KeyCode character in the ListBox. It finds the first record OK every time (for any character), and sets a module level variable to record its index and calls the ListBox AfterUpdate event (which applies the form filter etc). But when the same key is pressed a second time (looking for a second instance with the same first character) the list box flashes to the correct record (in the list box), applies the correct filter to the form but then reverts to the first record in the list starting with that character. The list box is therefore showing a different record to the form. If I break the code in the After Update event (using 'Stop') and then continue execution (using F5) after the filter is applied, all works as intended. I'm obviously missing something to do with ListBox behaviour, but what? -- Bob Darlington Brisbane |
#3
| |||
| |||
|
|
On Jan 5, 1:57 am, Bob Darlington<b... (AT) dpcman (DOT) com.au> wrote: The following is a follow up to a previous post. I'm using Access 2010 with a form containing a multi select list box. The code I'm using for the KeyPress event in the list box, calls the after update event for the same control which applies a filter to the form. THe KeyPress event tries to match a record starting with the KeyCode character in the ListBox. It finds the first record OK every time (for any character), and sets a module level variable to record its index and calls the ListBox AfterUpdate event (which applies the form filter etc). But when the same key is pressed a second time (looking for a second instance with the same first character) the list box flashes to the correct record (in the list box), applies the correct filter to the form but then reverts to the first record in the list starting with that character. The list box is therefore showing a different record to the form. If I break the code in the After Update event (using 'Stop') and then continue execution (using F5) after the filter is applied, all works as intended. I'm obviously missing something to do with ListBox behaviour, but what? -- Bob Darlington Brisbane Do you need to call the AfterUpdate event? I created the following code. When I do a keypress the AfterUpdate event is automatically called whether I set the listbox to Simple or None. Private Sub List0_AfterUpdate() MsgBox "AfterUpdate" End Sub Private Sub List0_KeyPress(KeyAscii As Integer) Debug.Print KeyAscii End Sub |
#4
| |||
| |||
|
|
On 6/01/2012 1:22 AM, Patrick Finucane wrote: On Jan 5, 1:57 am, Bob Darlington<b... (AT) dpcman (DOT) com.au> *wrote: The following is a follow up to a previous post. I'm using Access 2010 with a form containing a multi select list box. The code I'm using for the KeyPress event in the list box, calls the after update event for the same control which applies a filter to the form. THe KeyPress event tries to match a record starting with the KeyCode character in the ListBox. It finds the first record OK every time (for any character), and sets a module level variable to record its index and calls the ListBox AfterUpdate event (which applies the form filter etc). But when the same key is pressed a second time (looking for a second instance with the same first character) the list box flashes to the correct record (in the list box), applies the correct filter to the form but then reverts to the first record in the list starting with that character. The list box is therefore showing a different record to theform. If I break the code in the After Update event (using 'Stop') and then continue execution (using F5) after the filter is applied, all works as intended. I'm obviously missing something to do with ListBox behaviour, but what? -- Bob Darlington Brisbane Do you need to call the AfterUpdate event? *I created the following code. *When I do a keypress the AfterUpdate event is automatically called whether I set the listbox to Simple or None. Private Sub List0_AfterUpdate() * * *MsgBox "AfterUpdate" End Sub Private Sub List0_KeyPress(KeyAscii As Integer) * * *Debug.Print KeyAscii End Sub Thanks Patrick. I was using the AfterUpdate event to apply the filter to the form. It was called from the KeyPress, KeyDown and Click events. Following your post, I changed the code so that the filter is applied to the form from the individual events instead of calling the AfterUpdate to do the same thing. The problem however remains. Each time the filter is applied from the Keypress event, the value of the list box is reset to the first record starting with the KeyCode. The first selection works fine, but not when the same key is pressed a second time. It's also curious that the KeyPress and KeyDown events also result in calls to the Click event. ANy idea why that should be? And how can I differentiate between the event intitiated by actually clicking and that initiated from the KeyDown or KeyPress? The following is a code segment from the KeyPress event which seems to be causing the problem: * * * Me.Filter = "ContID = " & LstCont.ItemData(mIndex) * * * Me.FilterOn = True * * * LstCont.Selected(mIndex) = True mIndex is calculated correctly each time. The result is that the filter is correctly applied but the list box diplays the previous record. Sorry to be so long winded, but I hope you can help. -- Bob Darlington Brisbane- Hide quoted text - - Show quoted text - |
#5
| |||
| |||
|
|
On Jan 6, 1:48 am, Bob Darlington<b... (AT) dpcman (DOT) com.au> wrote: On 6/01/2012 1:22 AM, Patrick Finucane wrote: On Jan 5, 1:57 am, Bob Darlington<b... (AT) dpcman (DOT) com.au> wrote: The following is a follow up to a previous post. I'm using Access 2010 with a form containing a multi select list box. The code I'm using for the KeyPress event in the list box, calls the after update event for the same control which applies a filter to the form. THe KeyPress event tries to match a record starting with the KeyCode character in the ListBox. It finds the first record OK every time (for any character), and sets a module level variable to record its index and calls the ListBox AfterUpdate event (which applies the form filter etc). But when the same key is pressed a second time (looking for a second instance with the same first character) the list box flashes to the correct record (in the list box), applies the correct filter to the form but then reverts to the first record in the list starting with that character. The list box is therefore showing a different record to the form. If I break the code in the After Update event (using 'Stop') and then continue execution (using F5) after the filter is applied, all works as intended. I'm obviously missing something to do with ListBox behaviour, but what? -- Bob Darlington Brisbane Do you need to call the AfterUpdate event? I created the following code. When I do a keypress the AfterUpdate event is automatically called whether I set the listbox to Simple or None. Private Sub List0_AfterUpdate() MsgBox "AfterUpdate" End Sub Private Sub List0_KeyPress(KeyAscii As Integer) Debug.Print KeyAscii End Sub Thanks Patrick. I was using the AfterUpdate event to apply the filter to the form. It was called from the KeyPress, KeyDown and Click events. Following your post, I changed the code so that the filter is applied to the form from the individual events instead of calling the AfterUpdate to do the same thing. The problem however remains. Each time the filter is applied from the Keypress event, the value of the list box is reset to the first record starting with the KeyCode. The first selection works fine, but not when the same key is pressed a second time. It's also curious that the KeyPress and KeyDown events also result in calls to the Click event. ANy idea why that should be? And how can I differentiate between the event intitiated by actually clicking and that initiated from the KeyDown or KeyPress? The following is a code segment from the KeyPress event which seems to be causing the problem: Me.Filter = "ContID = "& LstCont.ItemData(mIndex) Me.FilterOn = True LstCont.Selected(mIndex) = True mIndex is calculated correctly each time. The result is that the filter is correctly applied but the list box diplays the previous record. Sorry to be so long winded, but I hope you can help. -- Bob Darlington Brisbane- Hide quoted text - - Show quoted text - Mostly I was just mentioning the AfterUpdate event fires after the KeyPress event and that maybe the double call was fouling things up. I admit I don't understand your problem. Let's say there's 2 records, one for Robert another for Roger. If I hit the R key 2 times I will be a Roger. Is your problem that the AU event resets back to Robert? Consider using a global variable or a TempVar to hold a value from the KeyPress result. You can get the values using ListIndex, ItemData, etc. Then filter using that variable instead of a keypress value. Thanks Patrick. |
#6
| |||
| |||
|
|
On 7/01/2012 1:37 AM, Patrick Finucane wrote: On Jan 6, 1:48 am, Bob Darlington<b... (AT) dpcman (DOT) com.au> *wrote: On 6/01/2012 1:22 AM, Patrick Finucane wrote: On Jan 5, 1:57 am, Bob Darlington<b... (AT) dpcman (DOT) com.au> * *wrote: The following is a follow up to a previous post. I'm using Access 2010 with a form containing a multi select list box.. The code I'm using for the KeyPress event in the list box, calls the after update event for the same control which applies a filter to the form. THe KeyPress event tries to match a record starting with the KeyCode character in the ListBox. It finds the first record OK every time (for any character), and sets a module level variable to record its indexand calls the ListBox AfterUpdate event (which applies the form filter etc). But when the same key is pressed a second time (looking for a second instance with the same first character) the list box flashes to the correct record (in the list box), applies the correct filter to the form but then reverts to the first record in the list starting with that character. The list box is therefore showing a different record to the form. If I break the code in the After Update event (using 'Stop') and then continue execution (using F5) after the filter is applied, all worksas intended. I'm obviously missing something to do with ListBox behaviour, but what? -- Bob Darlington Brisbane Do you need to call the AfterUpdate event? *I created the following code. *When I do a keypress the AfterUpdate event is automatically called whether I set the listbox to Simple or None. Private Sub List0_AfterUpdate() * * * MsgBox "AfterUpdate" End Sub Private Sub List0_KeyPress(KeyAscii As Integer) * * * Debug.Print KeyAscii End Sub Thanks Patrick. I was using the AfterUpdate event to apply the filter to the form. It was called from the KeyPress, KeyDown and Click events. Following your post, I changed the code so that the filter is applied to the form from the individual events instead of calling the AfterUpdate to do the same thing. The problem however remains. Each time the filter is applied from the Keypress event, the value of the list box is reset to the first record starting with the KeyCode. The first selection works fine, but not when the same key is pressed a second time. It's also curious that the KeyPress and KeyDown events also result in calls to the Click event. ANy idea why that should be? And how can I differentiate between the event intitiated by actually clicking and that initiated from the KeyDown or KeyPress? The following is a code segment from the KeyPress event which seems to be causing the problem: * * * *Me.Filter = "ContID = "& *LstCont.ItemData(mIndex) * * * *Me.FilterOn = True * * * *LstCont.Selected(mIndex) = True mIndex is calculated correctly each time. The result is that the filter is correctly applied but the list box diplays the previous record. Sorry to be so long winded, but I hope you can help. -- Bob Darlington Brisbane- Hide quoted text - - Show quoted text - Mostly I was just mentioning the AfterUpdate event fires after the KeyPress event and that maybe the double call was fouling things up. I admit I don't understand your problem. *Let's say there's 2 records, one for Robert another for Roger. *If I hit the R key 2 times I will be a Roger. *Is your problem that the AU event resets back to Robert? Consider using a global variable or a TempVar to hold a value from the KeyPress result. *You can get the values using ListIndex, ItemData, etc. *Then filter using that variable instead of a keypress value. Thanks Patrick. I've taken everything out of the AfterUpdate event now. The problem is as you describe and seems to occur when the Filter is run from within the KeyPress event. The variable 'mIndex' is a module level variable used to hold the position of the row in the list box. But after the filter, it moves back to the previous row, even though the filter was successfully applied. I've removed all form events to make sure nothing was triggered from there. I need to have a filter applied for KeyPress, KeyDown and Click events. It is a multiselect - Extended list box, and I want to be able to select mutilple non contiguous records using Ctrl + Click. The only problem is with the KeyPress event. (Note: I'll start a new thread regarding the Click event being called from other events, because I don't think it is necessarily related to this problem.) -- Bob Darlington Brisbane |
#7
| |||
| |||
|
|
On Jan 6, 5:29 pm, Bob Darlington<b... (AT) dpcman (DOT) com.au> wrote: On 7/01/2012 1:37 AM, Patrick Finucane wrote: On Jan 6, 1:48 am, Bob Darlington<b... (AT) dpcman (DOT) com.au> wrote: On 6/01/2012 1:22 AM, Patrick Finucane wrote: On Jan 5, 1:57 am, Bob Darlington<b... (AT) dpcman (DOT) com.au> wrote: The following is a follow up to a previous post. I'm using Access 2010 with a form containing a multi select list box. The code I'm using for the KeyPress event in the list box, calls the after update event for the same control which applies a filter to the form. THe KeyPress event tries to match a record starting with the KeyCode character in the ListBox. It finds the first record OK every time (for any character), and sets a module level variable to record its index and calls the ListBox AfterUpdate event (which applies the form filter etc). But when the same key is pressed a second time (looking for a second instance with the same first character) the list box flashes to the correct record (in the list box), applies the correct filter to the form but then reverts to the first record in the list starting with that character. The list box is therefore showing a different record to the form. If I break the code in the After Update event (using 'Stop') and then continue execution (using F5) after the filter is applied, all works as intended. I'm obviously missing something to do with ListBox behaviour, but what? -- Bob Darlington Brisbane Do you need to call the AfterUpdate event? I created the following code. When I do a keypress the AfterUpdate event is automatically called whether I set the listbox to Simple or None. Private Sub List0_AfterUpdate() MsgBox "AfterUpdate" End Sub Private Sub List0_KeyPress(KeyAscii As Integer) Debug.Print KeyAscii End Sub Thanks Patrick. I was using the AfterUpdate event to apply the filter to the form. It was called from the KeyPress, KeyDown and Click events. Following your post, I changed the code so that the filter is applied to the form from the individual events instead of calling the AfterUpdate to do the same thing. The problem however remains. Each time the filter is applied from the Keypress event, the value of the list box is reset to the first record starting with the KeyCode. The first selection works fine, but not when the same key is pressed a second time. It's also curious that the KeyPress and KeyDown events also result in calls to the Click event. ANy idea why that should be? And how can I differentiate between the event intitiated by actually clicking and that initiated from the KeyDown or KeyPress? The following is a code segment from the KeyPress event which seems to be causing the problem: Me.Filter = "ContID = "& LstCont.ItemData(mIndex) Me.FilterOn = True LstCont.Selected(mIndex) = True mIndex is calculated correctly each time. The result is that the filter is correctly applied but the list box diplays the previous record. Sorry to be so long winded, but I hope you can help. -- Bob Darlington Brisbane- Hide quoted text - - Show quoted text - Mostly I was just mentioning the AfterUpdate event fires after the KeyPress event and that maybe the double call was fouling things up. I admit I don't understand your problem. Let's say there's 2 records, one for Robert another for Roger. If I hit the R key 2 times I will be a Roger. Is your problem that the AU event resets back to Robert? Consider using a global variable or a TempVar to hold a value from the KeyPress result. You can get the values using ListIndex, ItemData, etc. Then filter using that variable instead of a keypress value. Thanks Patrick. I've taken everything out of the AfterUpdate event now. The problem is as you describe and seems to occur when the Filter is run from within the KeyPress event. The variable 'mIndex' is a module level variable used to hold the position of the row in the list box. But after the filter, it moves back to the previous row, even though the filter was successfully applied. I've removed all form events to make sure nothing was triggered from there. I need to have a filter applied for KeyPress, KeyDown and Click events. It is a multiselect - Extended list box, and I want to be able to select mutilple non contiguous records using Ctrl + Click. The only problem is with the KeyPress event. (Note: I'll start a new thread regarding the Click event being called from other events, because I don't think it is necessarily related to this problem.) -- Bob Darlington Brisbane Are all three events; KeyPress, KeyDown and Click events call the same filter routine? Do you have If statements in each routine? I think one of those events has keycode, another keyascii as a parameter. I don't recall if the values are the same for those parameters. IOW, maybe something is getting kicked off when it shouldn't. |
#8
| |||
| |||
|
|
On Jan 6, 5:29 pm, Bob Darlington<b... (AT) dpcman (DOT) com.au> wrote: On 7/01/2012 1:37 AM, Patrick Finucane wrote: On Jan 6, 1:48 am, Bob Darlington<b... (AT) dpcman (DOT) com.au> wrote: On 6/01/2012 1:22 AM, Patrick Finucane wrote: On Jan 5, 1:57 am, Bob Darlington<b... (AT) dpcman (DOT) com.au> wrote: The following is a follow up to a previous post. I'm using Access 2010 with a form containing a multi select list box. The code I'm using for the KeyPress event in the list box, calls the after update event for the same control which applies a filter to the form. THe KeyPress event tries to match a record starting with the KeyCode character in the ListBox. It finds the first record OK every time (for any character), and sets a module level variable to record its index and calls the ListBox AfterUpdate event (which applies the form filter etc). But when the same key is pressed a second time (looking for a second instance with the same first character) the list box flashes to the correct record (in the list box), applies the correct filter to the form but then reverts to the first record in the list starting with that character. The list box is therefore showing a different record to the form. If I break the code in the After Update event (using 'Stop') and then continue execution (using F5) after the filter is applied, all works as intended. I'm obviously missing something to do with ListBox behaviour, but what? -- Bob Darlington Brisbane Do you need to call the AfterUpdate event? I created the following code. When I do a keypress the AfterUpdate event is automatically called whether I set the listbox to Simple or None. Private Sub List0_AfterUpdate() MsgBox "AfterUpdate" End Sub Private Sub List0_KeyPress(KeyAscii As Integer) Debug.Print KeyAscii End Sub Thanks Patrick. I was using the AfterUpdate event to apply the filter to the form. It was called from the KeyPress, KeyDown and Click events. Following your post, I changed the code so that the filter is applied to the form from the individual events instead of calling the AfterUpdate to do the same thing. The problem however remains. Each time the filter is applied from the Keypress event, the value of the list box is reset to the first record starting with the KeyCode. The first selection works fine, but not when the same key is pressed a second time. It's also curious that the KeyPress and KeyDown events also result in calls to the Click event. ANy idea why that should be? And how can I differentiate between the event intitiated by actually clicking and that initiated from the KeyDown or KeyPress? The following is a code segment from the KeyPress event which seems to be causing the problem: Me.Filter = "ContID = "& LstCont.ItemData(mIndex) Me.FilterOn = True LstCont.Selected(mIndex) = True mIndex is calculated correctly each time. The result is that the filter is correctly applied but the list box diplays the previous record. Sorry to be so long winded, but I hope you can help. -- Bob Darlington Brisbane- Hide quoted text - - Show quoted text - Mostly I was just mentioning the AfterUpdate event fires after the KeyPress event and that maybe the double call was fouling things up. I admit I don't understand your problem. Let's say there's 2 records, one for Robert another for Roger. If I hit the R key 2 times I will be a Roger. Is your problem that the AU event resets back to Robert? Consider using a global variable or a TempVar to hold a value from the KeyPress result. You can get the values using ListIndex, ItemData, etc. Then filter using that variable instead of a keypress value. Thanks Patrick. I've taken everything out of the AfterUpdate event now. The problem is as you describe and seems to occur when the Filter is run from within the KeyPress event. The variable 'mIndex' is a module level variable used to hold the position of the row in the list box. But after the filter, it moves back to the previous row, even though the filter was successfully applied. I've removed all form events to make sure nothing was triggered from there. I need to have a filter applied for KeyPress, KeyDown and Click events. It is a multiselect - Extended list box, and I want to be able to select mutilple non contiguous records using Ctrl + Click. The only problem is with the KeyPress event. (Note: I'll start a new thread regarding the Click event being called from other events, because I don't think it is necessarily related to this problem.) -- Bob Darlington Brisbane Are all three events; KeyPress, KeyDown and Click events call the same filter routine? Do you have If statements in each routine? I think one of those events has keycode, another keyascii as a parameter. I don't recall if the values are the same for those parameters. IOW, maybe something is getting kicked off when it shouldn't. |
#9
| |||
| |||
|
|
On 8/01/2012 3:26 AM, Patrick Finucane wrote: On Jan 6, 5:29 pm, Bob Darlington<b... (AT) dpcman (DOT) com.au> *wrote: On 7/01/2012 1:37 AM, Patrick Finucane wrote: On Jan 6, 1:48 am, Bob Darlington<b... (AT) dpcman (DOT) com.au> * *wrote: On 6/01/2012 1:22 AM, Patrick Finucane wrote: On Jan 5, 1:57 am, Bob Darlington<b... (AT) dpcman (DOT) com.au> * * *wrote: The following is a follow up to a previous post. I'm using Access 2010 with a form containing a multi select list box. The code I'm using for the KeyPress event in the list box, calls the after update event for the same control which applies a filter to the form. THe KeyPress event tries to match a record starting with the KeyCode character in the ListBox. It finds the first record OK every time (for any character), and sets a module level variable to record its index and calls the ListBox AfterUpdate event (which applies the form filteretc). But when the same key is pressed a second time (looking for a second instance with the same first character) the list box flashes to the correct record (in the list box), applies the correct filter to the form but then reverts to the first record in the list starting with that character. The list box is therefore showing a different record tothe form. If I break the code in the After Update event (using 'Stop') and then continue execution (using F5) after the filter is applied, all works as intended. I'm obviously missing something to do with ListBox behaviour, but what? -- Bob Darlington Brisbane Do you need to call the AfterUpdate event? *I created the following code. *When I do a keypress the AfterUpdate event is automatically called whether I set the listbox to Simple or None. Private Sub List0_AfterUpdate() * * * *MsgBox "AfterUpdate" End Sub Private Sub List0_KeyPress(KeyAscii As Integer) * * * *Debug.Print KeyAscii End Sub Thanks Patrick. I was using the AfterUpdate event to apply the filter to the form. It was called from the KeyPress, KeyDown and Click events. Following your post, I changed the code so that the filter is applied to the form from the individual events instead of calling the AfterUpdate to do the same thing. The problem however remains. Each time the filter is applied from the Keypress event, the value of the list box is reset to the first record starting with the KeyCode. The first selection works fine, but not when the same key is pressed a second time. It's also curious that the KeyPress and KeyDown events also result in calls to the Click event. ANy idea why that should be? And how can I differentiate between the event intitiated by actually clicking and that initiated from the KeyDown or KeyPress? The following is a code segment from the KeyPress event which seems to be causing the problem: * * * * Me.Filter = "ContID = "& * *LstCont.ItemData(mIndex) * * * * Me.FilterOn = True * * * * LstCont.Selected(mIndex) = True mIndex is calculated correctly each time. The result is that the filter is correctly applied but the list box diplays the previous record. Sorry to be so long winded, but I hope you can help. -- Bob Darlington Brisbane- Hide quoted text - - Show quoted text - Mostly I was just mentioning the AfterUpdate event fires after the KeyPress event and that maybe the double call was fouling things up. I admit I don't understand your problem. *Let's say there's 2 records, one for Robert another for Roger. *If I hit the R key 2 times I will be a Roger. *Is your problem that the AU event resets back to Robert? Consider using a global variable or a TempVar to hold a value from the KeyPress result. *You can get the values using ListIndex, ItemData, etc. *Then filter using that variable instead of a keypress value. Thanks Patrick. I've taken everything out of the AfterUpdate event now. The problem is as you describe and seems to occur when the Filter is run from within the KeyPress event. The variable 'mIndex' is a module level variable used to hold the position of the row in the list box. But after the filter, it moves back to the previous row, even though the filter was successfully applied. I've removed all form events to make sure nothing was triggered from there. I need to have a filter applied for KeyPress, KeyDown and Click events.. It is a multiselect - Extended list box, and I want to be able to select mutilple non contiguous records using Ctrl + Click. The only problem is with the KeyPress event. (Note: I'll start a new thread regarding the Click event being called from other events, because I don't think it is necessarily related to this problem.) -- Bob Darlington Brisbane Are all three events; KeyPress, KeyDown and Click events call the same filter routine? *Do you have If statements in each routine? *I think one of those events has keycode, another keyascii as a parameter. *I don't recall if the values are the same for those parameters. *IOW, maybe something is getting kicked off when it shouldn't. Further to my earlier post, it makes no difference if the list box is not multi select. -- Bob Darlington Brisbane- Hide quoted text - - Show quoted text - |
#10
| |||
| |||
|
|
On Jan 9, 12:51 am, Bob Darlington<b... (AT) dpcman (DOT) com.au> wrote: On 8/01/2012 3:26 AM, Patrick Finucane wrote: On Jan 6, 5:29 pm, Bob Darlington<b... (AT) dpcman (DOT) com.au> wrote: On 7/01/2012 1:37 AM, Patrick Finucane wrote: On Jan 6, 1:48 am, Bob Darlington<b... (AT) dpcman (DOT) com.au> wrote: On 6/01/2012 1:22 AM, Patrick Finucane wrote: On Jan 5, 1:57 am, Bob Darlington<b... (AT) dpcman (DOT) com.au> wrote: The following is a follow up to a previous post. I'm using Access 2010 with a form containing a multi select list box. The code I'm using for the KeyPress event in the list box, calls the after update event for the same control which applies a filter to the form. THe KeyPress event tries to match a record starting with the KeyCode character in the ListBox. It finds the first record OK every time (for any character), and sets a module level variable to record its index and calls the ListBox AfterUpdate event (which applies the form filter etc). But when the same key is pressed a second time (looking for a second instance with the same first character) the list box flashes to the correct record (in the list box), applies the correct filter to the form but then reverts to the first record in the list starting with that character. The list box is therefore showing a different record to the form. If I break the code in the After Update event (using 'Stop') and then continue execution (using F5) after the filter is applied, all works as intended. I'm obviously missing something to do with ListBox behaviour, but what? -- Bob Darlington Brisbane Do you need to call the AfterUpdate event? I created the following code. When I do a keypress the AfterUpdate event is automatically called whether I set the listbox to Simple or None. Private Sub List0_AfterUpdate() MsgBox "AfterUpdate" End Sub Private Sub List0_KeyPress(KeyAscii As Integer) Debug.Print KeyAscii End Sub Thanks Patrick. I was using the AfterUpdate event to apply the filter to the form. It was called from the KeyPress, KeyDown and Click events. Following your post, I changed the code so that the filter is applied to the form from the individual events instead of calling the AfterUpdate to do the same thing. The problem however remains. Each time the filter is applied from the Keypress event, the value of the list box is reset to the first record starting with the KeyCode. The first selection works fine, but not when the same key is pressed a second time. It's also curious that the KeyPress and KeyDown events also result in calls to the Click event. ANy idea why that should be? And how can I differentiate between the event intitiated by actually clicking and that initiated from the KeyDown or KeyPress? The following is a code segment from the KeyPress event which seems to be causing the problem: Me.Filter = "ContID = "& LstCont.ItemData(mIndex) Me.FilterOn = True LstCont.Selected(mIndex) = True mIndex is calculated correctly each time. The result is that the filter is correctly applied but the list box diplays the previous record. Sorry to be so long winded, but I hope you can help. -- Bob Darlington Brisbane- Hide quoted text - - Show quoted text - Mostly I was just mentioning the AfterUpdate event fires after the KeyPress event and that maybe the double call was fouling things up. I admit I don't understand your problem. Let's say there's 2 records, one for Robert another for Roger. If I hit the R key 2 times I will be a Roger. Is your problem that the AU event resets back to Robert? Consider using a global variable or a TempVar to hold a value from the KeyPress result. You can get the values using ListIndex, ItemData, etc. Then filter using that variable instead of a keypress value. Thanks Patrick. I've taken everything out of the AfterUpdate event now. The problem is as you describe and seems to occur when the Filter is run from within the KeyPress event. The variable 'mIndex' is a module level variable used to hold the position of the row in the list box. But after the filter, it moves back to the previous row, even though the filter was successfully applied. I've removed all form events to make sure nothing was triggered from there. I need to have a filter applied for KeyPress, KeyDown and Click events. It is a multiselect - Extended list box, and I want to be able to select mutilple non contiguous records using Ctrl + Click. The only problem is with the KeyPress event. (Note: I'll start a new thread regarding the Click event being called from other events, because I don't think it is necessarily related to this problem.) -- Bob Darlington Brisbane Are all three events; KeyPress, KeyDown and Click events call the same filter routine? Do you have If statements in each routine? I think one of those events has keycode, another keyascii as a parameter. I don't recall if the values are the same for those parameters. IOW, maybe something is getting kicked off when it shouldn't. Further to my earlier post, it makes no difference if the list box is not multi select. -- Bob Darlington Brisbane- Hide quoted text - - Show quoted text - I created a continuous form with a listbox in the header. MsgBox Me.List9.ListIndex MsgBox Me.List9.Selected(Me.List9.ListIndex) MsgBox Me.List9.ItemData(Me.List9.ListIndex) The index is 0 based. Could that be an issue? The above code displays the current setting in the Keypress event and then moves to the correct record. I do not see why you fire the filter before it's on the correct record. I would fire it from the AfterUpdate event. I think you are beating yourself up needlessly. Thanks Patrick. |
![]() |
| Thread Tools | |
| Display Modes | |
| |