Error Handler problem No2!!!

Guirg

Registered User.
Local time
Today, 19:02
Joined
Jun 2, 2009
Messages
96
Hey all

trying to set up an error handler that raises an error if anything but a number is input into a text box it raises an error... Ive already got my error handler set up and working beautifully its just this im struggling with

Code:
    If IsNumeric(Me.txtMin.value) = False Then
        Raise.Err 1
    End If
    If IsNumeric(Me.txtMax.value) = False Then
        Raise.Err 1
    End If
    If IsNumeric(Me.txtMIN_1.value) = False Then
        Raise.Err 1
    End If
    If IsNumeric(Me.txtMAX_1.value) = False Then
        Raise.Err 1
    End If

Thanks

Guirg
 
I gather you fixed your own dilemma...

Just a thought, why not trap and stop any other keys at the time of input?

Use a Function such as...
Code:
Function OnlyNumKeys(KeyAscii As Integer) As Integer
Select Case KeyAscii
Case 8, 46, 48 To 57 'allow backspace, period, and numbers
Case 13 'do sommit with the enter key if you like
Case Else: KeyAscii = 0 'reject everything else
End Select
OnlyNumKeys= KeyAscii
End Function

...and then trap it using the On Key Press event...
Code:
Private Sub TxtMin_KeyPress(KeyAscii As Integer)
    KeyAscii = OnlyNumKeys(KeyAscii)
End Sub

Saves a lot of extra trapping.

Regards Brett
 
that makes alot of sense actually, what i was forgetting was that i made it possible to have an empty text box which null isnt a number it was popping up and error so what i ended up with was
Code:
If Me.txtMin > "" Then
    If IsNumeric(Me.txtMin) = False Then
        Raise.Err 1
    End If
End If
If Me.txtMax > "" Then
    If IsNumeric(Me.txtMax) = False Then
        Raise.Err 1
    End If
End If
If Me.txtMIN_1 > "" Then
    If IsNumeric(Me.txtMIN_1) = False Then
        Raise.Err 1
    End If
End If
If Me.txtMAX_1 > "" Then
    If IsNumeric(Me.txtMAX_1) = False Then
        Raise.Err 1
    End If
End If
 
guirg

do you realise you can just set the field type of the textbox

set it as generalnumber, or fixed number of decimal places etc
and all this is done for oyu - the textbox just wont accept letters

also if you BIND the field to a control source, then the field typing is done automatically for you
 
Yes i realise i can do that but as the computers at work here are german and the data can sometimes be american they have 2 different decimal place systems germans use "," and americans ".".... and the data is in "." which means that when i went to set the field it used "," and poped an error up with "." so when i typed "," it came up with a formating error... hence the code above :D
 
I agree Dave however sometimes it is nice to simply stop the user from entering the wrong data type in the first place. That way no error message pops up at all so a more professional looking presentation.

REgards Brett
 
no im not disagreeing im just saying its not possible in this case due to the mix of different systems the German and American use different decimal symbols, date order.. same reason the date filter had to have a whole bunch of extra coding so it would be usable for both systems without either producing no results or not lettign the filter work...
 
well not sure of all the details but you can use keypress event to examine the keystroke (witihn the control) BEFORE processing it - rather than using error handlers - might be useful?
 
Dave...

That's what I have proposed (see third screen from the top).
 
Cheers for the help guys, It doesnt really matter anyway its an inhouse program and my chance to improve my understanding of VB and how annoying it can be... error handelings somethign ive never attempted so hence the attack above :)
 
I would have to agree with the idea of the key press event. Except instead of issuing errors I would just delete the character that they entered. Let them type letters all day, just don't allow it to enter the box. This would be less annoying when you fat finger the number keys up top while typing.
 

Users who are viewing this thread

Back
Top Bottom