dbTalk Databases Forums  

ListBox KeyPress Problem

comp.databases.ms-access comp.databases.ms-access


Discuss ListBox KeyPress Problem in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Bob Darlington
 
Posts: n/a

Default ListBox KeyPress Problem - 01-05-2012 , 01:57 AM






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

Reply With Quote
  #2  
Old   
Patrick Finucane
 
Posts: n/a

Default Re: ListBox KeyPress Problem - 01-05-2012 , 09:22 AM






On Jan 5, 1:57*am, Bob Darlington <b... (AT) dpcman (DOT) com.au> wrote:
Quote:
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

Reply With Quote
  #3  
Old   
Bob Darlington
 
Posts: n/a

Default Re: ListBox KeyPress Problem - 01-06-2012 , 01:48 AM



On 6/01/2012 1:22 AM, Patrick Finucane wrote:
Quote:
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

Reply With Quote
  #4  
Old   
Patrick Finucane
 
Posts: n/a

Default Re: ListBox KeyPress Problem - 01-06-2012 , 09:37 AM



On Jan 6, 1:48*am, Bob Darlington <b... (AT) dpcman (DOT) com.au> wrote:
Quote:
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 -
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.

Reply With Quote
  #5  
Old   
Bob Darlington
 
Posts: n/a

Default Re: ListBox KeyPress Problem - 01-06-2012 , 05:29 PM



On 7/01/2012 1:37 AM, Patrick Finucane wrote:
Quote:
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

Reply With Quote
  #6  
Old   
Patrick Finucane
 
Posts: n/a

Default Re: ListBox KeyPress Problem - 01-07-2012 , 11:26 AM



On Jan 6, 5:29*pm, Bob Darlington <b... (AT) dpcman (DOT) com.au> wrote:
Quote:
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
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.

Reply With Quote
  #7  
Old   
Bob Darlington
 
Posts: n/a

Default Re: ListBox KeyPress Problem - 01-09-2012 , 12:29 AM



On 8/01/2012 3:26 AM, Patrick Finucane wrote:
Quote:
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.
Thanks again Patrick.
The filters are different depending on which event triggers them and
I've included module level variables to avoid multiple calls and
isolated the KeyDown and Click events for testing.

The relevant code segment (after finding the correct row) in the
KeyPress event is:

Msgbox mIndex returns 36 (correct)
me!lstbox.Selected(mIndex) = True
Me.Filter = "ContID = " & .ItemData(mIndex)
Me.FilterOn = True

At this stage, if the code is interrupted with a message box, the filter
has been successfully applied to main form and the screen shows that
item 36 is selected in the List box.
But when the message box is cleared, the form remains with the same
filter, but item 35 (the previous row) is selected in the list box.
If the filter is remmed out, the list selection works exactly as
intended. There is nothing in the main form to affect the list box.
It only happens when the same character key is pressed a second time.

If I use:
me!lstBox.Selected(mIndex) = True
either in the KeyPress (after the filter) or before or after update
events, then it makes no difference.

--
Bob Darlington
Brisbane

Reply With Quote
  #8  
Old   
Bob Darlington
 
Posts: n/a

Default Re: ListBox KeyPress Problem - 01-09-2012 , 12:51 AM



On 8/01/2012 3:26 AM, Patrick Finucane wrote:
Quote:
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

Reply With Quote
  #9  
Old   
Patrick Finucane
 
Posts: n/a

Default Re: ListBox KeyPress Problem - 01-09-2012 , 10:10 AM



On Jan 9, 12:51*am, Bob Darlington <b... (AT) dpcman (DOT) com.au> wrote:
Quote:
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 -
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.

Reply With Quote
  #10  
Old   
Bob Darlington
 
Posts: n/a

Default Re: ListBox KeyPress Problem - 01-09-2012 , 03:59 PM



On 10/01/2012 2:10 AM, Patrick Finucane wrote:
Quote:
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.
No, the index isn't a problem, but that was one of the first things I
checked.
I tried the filter on the after update event before I moved it to the
KeyPress.
I might start another thread with a clearer definition of the problem as
it has emerged during this thread.
--
Bob Darlington
Brisbane

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.