Click to See Complete Forum and Search --> : Keydown still causing a beep after setting KeyCode=0


obiwan444
July 16th, 2001, 10:58 AM
This is a very wierd issue which occurs on one form of an MDI application I am working on. I have placed toolbars at the bottoms of my forms to replace having a row of command buttons (just for looks). Unfortunately I lost the keyhandlers that came along with the command buttons and had to write them manually in the keydown event handler of the form. This works great on 4/5 forms in the app. On one form however, I always get a beep when an alt+key sequence is pressed. I'm trapping the alt+key sequences and calling the cooresponding sub after setting the keycode=0, but I still get the beep. Other forms using similar logic/code do not beep. Below is my code ... does anyone have a suggestion of something I may be overlooking?

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim AltDown As Integer

AltDown = (Shift And vbAltMask) > 0
KeyAscii = Asc(UCase(Chr(KeyCode)))

' ignore function keys
If KeyCode >= vbKeyF1 And KeyCode <= vbKeyF16 Then
KeyCode = 0
Exit Sub
End If

' if the alt key is pressed, check for alt+key combinations
If AltDown Then

Select Case KeyAscii
Case vbKeyN: KeyCode = 0: cmdCollectionsAdd_Click
Case vbKeyC: KeyCode = 0: cmdCaseAdd_Click
Case vbKeyL: KeyCode = 0: cmdCollectionsDelete_Click
Case vbKeyB: KeyCode = 0: cmdDebtorDelete_Click
Case vbKeyS: KeyCode = 0: cmdCaseDelete_Click
Case vbKeyG: KeyCode = 0: cmdSaveChanges_Click
Case vbKeyR: KeyCode = 0: cmdDebtorAdd_Click
End Select

End If ' if alt key down

End Sub

sotoasty
July 16th, 2001, 02:56 PM
Just a wild guess, is the KeyPreview property of the form, different than the ones that work?

obiwan444
July 16th, 2001, 03:16 PM
thx for the reply, but no ... the keypreview property is set to true on all forms (meant to mention that in the original post).

-obiwan

obiwan444
July 16th, 2001, 03:45 PM
i've discovered that the beep only occurs when i use an alt+key sequence (keyboard shortcut) and the active control is not a masked edit control. i added a masked edit control to the form and when it has the focus, the keydown events are handled, the subs are executed, and there is no beep. if any other control has the focus, it beeps. whack, eh ?

-obiwan