Input Mask Code

Input Mask Code

am 14.11.2007 00:16:22 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: Input Mask Code

am 14.11.2007 15:12:50 von Salad

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.

I doubt you'd want an input mask if you are forcing the numbers to be
right justified.

I might try this. Let's say you have a field called Code. You know it
will always begin with B. Why force the op to enter B? And a Dash?
There's no purpose to that besides more data entry on the part of the
end user.

Drop Code onto the form and make it Visible=No. Now create a new text
box and call it CodeNum, no control source. Set the default value to 0.
Now when a person enters data, in the BeforeUpdate event of CodeNum,
do something like
If Not Isnumeric("CodeNum") then
msgbox "Please enter a number"
Cancel = True
Endif

If the op attempts to enter a alpha char, it won't permit it.

In the AfterUpdate event of CodeNum do something like
Me.Code = "B-" & Right("0000000" & Me.CodeNum,7)
and this will concatenate the two together to make your code number meet
your mask.

Inside
http://www.youtube.com/watch?v=MSKEBEC_zXk


>
> 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: Input Mask Code

am 14.11.2007 18:08:00 von u37558

Hi -

It's easy. Set the input mask of the text box to B-9999999;0 (The ;0 part
forces the B- to be retained as part of the data)

Then, in the after update event of the text box, use:

Text0 = Left(Text0, 2) & Format(Mid(Text0, 3), "0000000")

to format it with the leading zeros. This does what you need, I think.

John


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

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/databases-ms-ac cess/200711/1