Message 1 of 6
Validating Data
Not applicable
11-29-1999
06:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Matt,
I agree with not allowing invalid data to be entered in the first place.
Where exactly should I paste the code starting with "public..."? I copied
it to the keypress event of the text box but the public line becomes red and
when I try to run the app, it tells me I have a compile error.
Thanks...
Scott
PS- I pasted the function into the 'general' module
Matt Slay wrote in message
news:[email protected]...
> I just wanted to make sure you saw my reply to your earlier post.
>
> If you implement this KeyPress approach, the user's input will be limited
> to numeric characters ONLY, and there is NO WAY they can enter bad data to
> start with, then you do not have to worry about a message or about setting
> focus.
>
>
> Here is a function that I add to my programs, then make a call to it from
> the keypress event of the textbox:
>
> Public TextBox1.Keypress (KeyAscii as Integer)
> KeyAscii=Num_Check(KeyAscii)
> EndSub
>
>
>
> Function Num_Check(KeyAscii As Integer)
>
> '-- Only allows digits 0-9 and one decimal
> '-- (no negatives and no alpha characters)
>
> If KeyAscii <> vbKeyBack Then
>
> If KeyAscii = vbKeyReturn Then
> SendKeys "{TAB}"
> KeyAscii = 0
> ElseIf Chr(KeyAscii) = "." And InStr(ActiveControl, ".") = 0 Then
> KeyAscii = KeyAscii
> ElseIf Chr(KeyAscii) < "0" Or Chr(KeyAscii) > "9" Then
> KeyAscii = 0
> End If
>
> End If
>
> Num_Check = KeyAscii
>
> End Function
>
>
>
>
>
I agree with not allowing invalid data to be entered in the first place.
Where exactly should I paste the code starting with "public..."? I copied
it to the keypress event of the text box but the public line becomes red and
when I try to run the app, it tells me I have a compile error.
Thanks...
Scott
PS- I pasted the function into the 'general' module
Matt Slay
news:[email protected]...
> I just wanted to make sure you saw my reply to your earlier post.
>
> If you implement this KeyPress approach, the user's input will be limited
> to numeric characters ONLY, and there is NO WAY they can enter bad data to
> start with, then you do not have to worry about a message or about setting
> focus.
>
>
> Here is a function that I add to my programs, then make a call to it from
> the keypress event of the textbox:
>
> Public TextBox1.Keypress (KeyAscii as Integer)
> KeyAscii=Num_Check(KeyAscii)
> EndSub
>
>
>
> Function Num_Check(KeyAscii As Integer)
>
> '-- Only allows digits 0-9 and one decimal
> '-- (no negatives and no alpha characters)
>
> If KeyAscii <> vbKeyBack Then
>
> If KeyAscii = vbKeyReturn Then
> SendKeys "{TAB}"
> KeyAscii = 0
> ElseIf Chr(KeyAscii) = "." And InStr(ActiveControl, ".") = 0 Then
> KeyAscii = KeyAscii
> ElseIf Chr(KeyAscii) < "0" Or Chr(KeyAscii) > "9" Then
> KeyAscii = 0
> End If
>
> End If
>
> Num_Check = KeyAscii
>
> End Function
>
>
>
>
>