Full Version: Data Validation
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
Puckins
Hi there

I have a form which I need to enter a mobile phone base station ID which is currently in the form of "any number of numerical characters" followed by a single alphanumeric option letter
eg
104A
11086B
23248D
15E

etc. Technically any number of numeric characters should be allowed, but a safe limit would be 7 numeric characters and one alphanumeric at the right end of the ID.

Leading zeros are not an option, as this has to mesh into reports produced by another existing system which omits the leading zeros.

Short of asking users to enter spaces manually, I can't think of a way to make the input mask fill from the right instead of the left, so that I could use 9999990L

If anyone has any ideas, I'd love to hear them!
adamsherring
Hi,

try this function on for size (air code coming),

CODE
public function validatePhone(sPhone as string) as boolean
    validatephone =false

    if not isnum(left(sphone),len(sphone)-1) then exit function
    if not isAlpha(right(sphone,1)) then exit function

    validatephone = true

end function

Public Function isAlpha(cChar As Integer) As Boolean    'returns if its a alphabetic character
    isAlpha = IIf((cChar >= 65 And cChar <= 90) Or (cChar >= 97 And cChar <= 122), True, False)
End Function


Public Function isNum(varTest) As Boolean
    Dim numTest As Long
    
    isNum = False
    
    On Error GoTo notnumber
    
    numTest = varTest
    If numTest <> varTest Then GoTo notnumber
    isNum = True
    Exit Function
    
notnumber:

End Function


The isNum function will check if its a number or not (as a long), and the isAlpha function will check if it is a letter, lowercase or uppercase.

Hope these come in handy for ya,

Adam
Puckins
Ahh, that makes sense,

I've not had much experience of access, so i've got this snazzy table structure all defined and I'm scratching my head to get decent forms together! I can see I'm going to have to learn VB to complete this project properly. Cheers for the help.
adamsherring
Glad I could help.

Since you're new to Access, let me point you towards this post , which will give you lots of great little tips (Scroll down to see Freakazeud's links).

Good luck,

Adam
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.