Coding for a Range

JennJenn

Registered User.
Local time
Today, 09:42
Joined
May 15, 2002
Messages
13
I only want a user to enter either a number, decimal point, or negative operator in the the first three positions in the control.

This is the code I used:

Dim MyNumber
MyNumber = Left(FieldName, 3)

If MyNumber = "A through Z" Then
MsgBox "Non-numeric characters are not allowed in this positon. Please enter value again."
FieldName.Value.Reset
FieldName.SetFocus
Exit Sub
End If

I'm having problems with the line:
If MyNumber = "A through Z"

I don't know how to define the range in code for saying any letter from a through z. Or to define a way for the user to not enter anything other than a number, negative operator (-), or a decimal point (.).

Can anyone help me out with this?

[This message has been edited by JennJenn (edited 05-31-2002).]

Thanks David (Access Expert). You're good!!

[This message has been edited by JennJenn (edited 05-31-2002).]
 
Code:
Private Sub Text0_BeforeUpdate(Cancel As Integer)
    Dim st As Integer, i As Byte, j As Byte
        
    If IsNull(Me.Text0) Then Exit Sub 'no text to check
    
    j = Len(Me.Text0)
    If j > 3 Then j = 3 'don't want to overrun the length
    
    For i = 1 To j
    st = Asc(Mid(Me.Text0, i, 1))
    If (st > 57 Or st < 45) Or st = 47 Then 'anything but 0-9  - .
        MsgBox "Please enter only a number, -, or . in the first three characters of the field."
        Cancel = True
        Exit Sub
    End If
    
    Next i 'data was safe, go to next space
    
End Sub
 

Users who are viewing this thread

Back
Top Bottom