1
votes


I have userform with textboxes. Textbox restricts input of some character or rather allows input of numbers commas and dots. Code is within key_press event of textbox. Everything works fine as long as code below is in the key_press event. When I enter call private sub with same code from different sub it does not work.

Why it does not work?

Code within Key_press event:

Private Sub netto_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

Select Case KeyAscii

    Case Asc("0") To Asc("9")
    Case Asc("-")
    Case Else
    KeyAscii = 0

End Select

End Sub

Code with call sub within Key_press event:

Private Sub netto_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

Call klawisze

End Sub

Private Sub klawisze()

Select Case KeyAscii

    Case Asc("0") To Asc("9")
    Case Asc("-")
    Case Else
    KeyAscii = 0

End Select

End Sub
1
have you set a breakpoint and debugged it to see what it's doing?rory.ap
Actually I executed it line by line using "step into" and well nothing really happend. Event called private sub, private sub executed as it should and nothing... still working wrong.lowak

1 Answers

1
votes

You where close to the right solution. You simply need to pass argument KeyAscii in your klawisze sub (which accept corresponding parametr: ByVal KeyAscii As MSForms.ReturnInteger):

Private Sub netto_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Call klawisze(KeyAscii)
End Sub

Private Sub klawisze(ByVal KeyAscii As MSForms.ReturnInteger)
    Select Case KeyAscii
        Case Asc("0") To Asc("9")
        Case Asc("-")
        Case Else
            KeyAscii = 0
    End Select
End Sub