Access Input Mask Code

Access Input Mask Code

am 14.11.2007 00:26:33 von c.kurutz

I 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

Re: Access Input Mask Code

am 14.11.2007 07:39:34 von MGFoster

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Here's an easier way.

1. Put the following mask in the Text Box:

Input Mask: "B-"9999999;;_

2. Then put this code in the TextBox's AfterUpdate event:

Private Sub OrderNumber_AfterUpdate()

Me!OrderNumber = Format(Me!OrderNumber, "0000000")

End Sub

The user only has to enter the numeric value. The mask will put in the
capital 'B'. The Format() function will insert the leading zeros, if
needed.

--
MGFoster:::mgf00 earthlink net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRzqYHoechKqOuFEgEQJH3QCfa4m0vly2LENejyKlqSqzwwgMVqIA oIO9
THcimRXf1pEvdCXofmc5u41F
=UW1X
-----END PGP SIGNATURE-----


clk wrote:
> I 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
>