Douglas Cummings
asked on
How do I suppress the character on a KeyDown event
I have a form with 2 sub forms for the purpose of entering financial data. I want the user to be able to move between the main forn and subforms by entering the forward slash character on the numeric keypad. My code works as intended, but it leaves the "/" character behind when intitiated from either of the subforms. It does not from the main form. How do I suppress the "/" from appearing in my field?
Main Form Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyDivide
Me.frmDescriptionSubform.S etFocus
End Select
End Sub
(This works and does not leave the "/" character.)
Subform 1 Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyDivide
Screen.ActiveForm.[frmMeta lsSubform] .SetFocus
End Select
End Sub
(This works as far a movement, but leaves the "/" character.)
Subform 2 Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyDivide
Screen.ActiveForm.[Comb08] .SetFocus
End Select
End Sub
(This works as far a movement, but leaves the "/" character.)
Main Form Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyDivide
Me.frmDescriptionSubform.S
End Select
End Sub
(This works and does not leave the "/" character.)
Subform 1 Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyDivide
Screen.ActiveForm.[frmMeta
End Select
End Sub
(This works as far a movement, but leaves the "/" character.)
Subform 2 Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyDivide
Screen.ActiveForm.[Comb08]
End Select
End Sub
(This works as far a movement, but leaves the "/" character.)
To suppress the key that was pressed, set the KeyCode value to 0
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Not sure if this will work as i have not tried this myself, but have you set the KeyPreview property on the form to Yes?
If you do this, try the following
If you do this, try the following
Select Case KeyCode
Case vbKeyDivide
KeyCode = 0
Screen.ActiveForm.[Comb08].SetFocus
End Select
damn got beaten to it, taking too long editing. Oh well at least someone agrees with my suggestion
ASKER
Thanks for the help.
I used your code, except that it doesn't work with "Case" in the if statement. I used the following:
If KeyCode = vbKeyDivide Then
Screen.ActiveForm.[Combo8] .SetFocus
KeyCode = 0
End if
Again, thanks.
I used your code, except that it doesn't work with "Case" in the if statement. I used the following:
If KeyCode = vbKeyDivide Then
Screen.ActiveForm.[Combo8]
KeyCode = 0
End if
Again, thanks.