Access Input Mask Code
am 14.11.2007 00:26:33 von c.kurutzI am working on a database someone else created. I need to modify the
code for the order number field. I need the input mask to be
"B-000000". It should allow for seven digits and a prefix of "B-". I
would like to enter 123 and for the field to then read B-0000123.
Any help would be greatly appreciated.
CODE FROM FORM:
Private Sub ordernumber_Change()
Dim dummy As String
Dim ilong As Long
Static inthissub As Long
If inthissub = 0 Then
inthissub = -1
If dontmask = 0 Then
If ordernumber.Text <> ordnmbrfromfile Then
ilong = ordernumber.SelStart
dummy = ordernumber.Text
ilong = ilong + maskme(dummy, ordernumbermask)
ordernumber.Text = dummy
ordernumber.SelLength = 0
ordernumber.SelStart = ilongUse
End If
End If
inthissub = 0
End If
charcount.Caption = Len(ordernumber.Text) doesmatch0.Caption =
matchornot(1) End Sub
ORDERNUMBERMASK FUNCTION:
Public Const ordernumbermask = "&-#######"
MASKME FUNCTION:
Public Function maskme(thisstring As String, ByVal delimiter As
String) As Long
Dim dummy As String
Dim otherdummy As String
Dim ii_delimiter As Long
Dim ii_dummy As Long
Dim ii_other As Long
Dim jj As Long
Dim counter As Long
Dim maxlen As Long
dummy = thisstring
ii_delimiter = 1
ii_dummy = 1
ii_other = 1
If Left$(thisstring, 1) <> nomaskchar Then
Do While ii_dummy <= Len(dummy) And ii_delimiter <= Len(delimiter)
Select Case Mid$(delimiter, ii_delimiter, 1)
Case "#" 'use number
If IsNumeric(Mid$(dummy, ii_dummy, 1)) Then
otherdummy = otherdummy & Mid$(dummy, ii_dummy, 1)
ii_dummy = ii_dummy + 1
End If
Case "&" 'use alpha
If UCase$(Mid$(dummy, ii_delimiter, 1)) = Chr$(Asc(Mid
$ (dummy, ii_delimiter, 1)) And &HDF) Then
otherdummy = otherdummy & UCase$(Mid$(dummy,
ii_dummy, 1))
ii_dummy = ii_dummy + 1
Else
otherdummy = otherdummy & "B"
End If
Case Else
If Mid$(delimiter, ii_delimiter, 1) <> Mid$(dummy,
ii_dummy, 1) Then
otherdummy = otherdummy & Mid$(delimiter,
ii_delimiter, 1)
counter = counter + 1
Else
otherdummy = otherdummy & Mid$(dummy, ii_dummy, 1)
ii_dummy = ii_dummy + 1
End If
End Select
ii_delimiter = ii_delimiter + 1
Loop
ii_dummy = ii_dummy - 1
If ii_dummy < Len(dummy) Then
otherdummy = otherdummy & Right$(dummy, Len(dummy) -
(ii_dummy))
End If
maskme = counter + 1
thisstring = otherdummy
Else
maskme = 0
End If
End Function