Input Mask / Format

  • Thread starter Thread starter theBIGmr
  • Start date Start date
T

theBIGmr

Guest
Hiya everyone,
I'm try to do a database for items with part numbers.
& I want to be able to set the field to only accept data which has two letters at the begining, but any other characters after that (no fixed size).

ie.
part num1: pn047589sdf8m3
part num2: pn6583
part num3: pnfdgmj5973m
part num4: pn-fdgmj-5973m

Is this possible to do?

Cos all I can do at the moment, is to put a fixed number of characters.
ie. is the field size is 30characters
then I'd have to do this:
>LLCCCCCCCCCCCCCCCCCCCCCCCCCCCC

but this isn't good.

I just need something like:
>LL*

* mean any character for as many characters in length.

Adam
BIGmrC
 
This might work for you. Put this in a general module.

Code:
Public Function VPN2( PN as String ) as Boolean
Dim PNOK as Boolean

If Len(PN) > 1              'be sure we have 2 characters
  Then
    PNOK = True            'could be valid
  Else
    PNOK = False           'cannot be valid
    GoTo SendVPN2
  End If

Select Case Mid( PN, 1, 1 )
  Case "A" to "Z"           'OK if in range uppercase A to Z
  Case "a" to "z"            'OK if in range lowercase a to z
  Case Else
    PNOK = False           'not in right range 
    GoToSendVPN2
  End Select

Select Case Mid( PN, 2, 1 )
  Case "A" to "Z"           'same tests, 2nd character
  Case "a" to "z"
  Case Else
    PNOK = False
    GoToSendVPN2
  End Select

SendVPN2:
    VPN2 = PNOK
End Function

Then you will get either True or False (Yes or No) when you use the function.

E.G.

VPN2( "1A") returns False (1st char. not alphabetic)
VPN2( "A1") returns False (2nd char. not alphabetic)
VPN2( " 1" ) returns False (1st char. not alphabetic)
VPN2( "A" ) returns False (no testable 2nd character)
VPN2("AB123") returns True

It is usable in queries, forms, and reports. (And in other VBA code.)
 
Thanks The_Doc_Man.

I'll try it now.

Cheers
Adam Courthold
BIGmrC
 

Users who are viewing this thread

Back
Top Bottom