Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Event Suppressions... 2

Status
Not open for further replies.

skinicod

Programmer
Sep 9, 2003
46
GB
Hi,

I have a listbox which uses two events, the first is the Click event and the other is the KeyDown Event.

If a user clicks on the listbox I want it to do one thing, and if the user spins through using the up and down arrows I want it to do another thing.

My code looks something like this:

Private Sub LstField_Click()
'Do some function 1
End Sub

Private Sub LstField_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then
'Do Some function 2
ElseIf KeyCode = vbKeyDown Then
'Do Some function 3
End If
End Sub

The problem is that after pressing vbKeyDown or vbKeyup my code runs through the KeyDown event, but then goes on to run through the Click event. Does anyone know a way to stop the click event happening after the keydown event??

Ideas would be gratefully recieved.

Cheers,

Skinicod
 
Hi!

One idea would be to use a form public variable to store whether the arrow keys where used or not in the keydown event, and then check that when the on click event occurs. If MyKey don't run the event (note - set it to true after the click event is run). Perhaps something like this:

[tt]Private Sub LstField_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then
'Do Some function 2
MyKey=False
ElseIf KeyCode = vbKeyDown Then
'Do Some function 3
MyKey=False
End If
End Sub[/tt]

[tt]Private Sub LstField_Click()
if MyKey then
'Do some function 1
MyKey = True
end if
end sub[/tt]

Roy-Vidar
 
Erm - would probably have the listclic MyKey=True outside the iftest - Roy-Vidar
 
Hi

Option Compare Database
Option Explicit
Dim blnKeyDown As Boolean

Private Sub List0_Click()
If blnKeyDown Then
blnKeyDown = False
Else
MsgBox "click"
End If
End Sub

Private Sub List0_KeyDown(KeyCode As Integer, Shift As Integer)
blnKeyDown = True
Select Case KeyCode
Case vbKeyUp
Debug.Print "keyup"
Case vbKeyDown
Debug.Print "keydown"
End Select
End Sub

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Of course!!

Please put my inability down to it being Monday...

Cheers,

Paul.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top