Link to home
Start Free TrialLog in
Avatar of Douglas Cummings
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.SetFocus
    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.[frmMetalsSubform].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.)

Avatar of Dale Fye
Dale Fye
Flag of United States of America image

To suppress the key that was pressed, set the KeyCode value to 0
ASKER CERTIFIED SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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  
Select Case KeyCode
        Case vbKeyDivide
            KeyCode = 0
            Screen.ActiveForm.[Comb08].SetFocus
End Select

Open in new window

damn got beaten to it, taking too long editing.  Oh well at least someone agrees with my suggestion
Avatar of Douglas Cummings
Douglas Cummings

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.