lowak
lowak

Reputation: 1284

Userform events and calling private sub


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

Upvotes: 1

Views: 2244

Answers (1)

Dmitry Pavliv
Dmitry Pavliv

Reputation: 35863

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

Upvotes: 1

Related Questions