From: terry w on
hi experts - I am quite new to this. I have a txtbox on my bound form called
txWorkCode. It is a required field and duplicates are not allowed. I want
it to accept only digits 0 to 9 (but they are text, not integers). If the
user enters 3 for example, I want a "0" appended to the front. In other
words the underlying table will always be from 00 to 99 whether the user
enters 1 digit or 2.

I don't want the value to just 'look' like "03" for example, but I need
there to actually be "03" in the WorkCode field in my underlying table.

If it's not too much to ask from the experts I'd like to know how to do this
with Input Mask or Format if possible, but I'd also like to learn how to do
it using VBA. very many thanks

Terrance
From: John W. Vinson on
On Fri, 19 Mar 2010 15:48:01 -0700, terry w <terryw(a)discussions.microsoft.com>
wrote:

>hi experts - I am quite new to this. I have a txtbox on my bound form called
>txWorkCode. It is a required field and duplicates are not allowed. I want
>it to accept only digits 0 to 9 (but they are text, not integers). If the
>user enters 3 for example, I want a "0" appended to the front. In other
>words the underlying table will always be from 00 to 99 whether the user
>enters 1 digit or 2.
>
>I don't want the value to just 'look' like "03" for example, but I need
>there to actually be "03" in the WorkCode field in my underlying table.
>
>If it's not too much to ask from the experts I'd like to know how to do this
>with Input Mask or Format if possible, but I'd also like to learn how to do
>it using VBA. very many thanks
>
>Terrance

You could use an inputmask of

90

to force entry of only digits, but allow one or two to be entered; then in the
textbox's AfterUpdate event put code like

Private Sub txWorkCode_AfterUpdate()
If Len(Me!txWorkCode) < 2 Then
Me!txWorkCode = Right("00" & Me!txWorkCode, 2)
End If
End Sub

One suggestion: if there is a limited number of work codes, why not give the
user a Combo Box showing the list, and letting them just select one? This
could even allow you to show a human-meaningful translation rather than just
two digits.
--

John W. Vinson [MVP]
From: terry w on
John - thanks! I'll take your advice.

"John W. Vinson" wrote:

> On Fri, 19 Mar 2010 15:48:01 -0700, terry w <terryw(a)discussions.microsoft.com>
> wrote:
>
> >hi experts - I am quite new to this. I have a txtbox on my bound form called
> >txWorkCode. It is a required field and duplicates are not allowed. I want
> >it to accept only digits 0 to 9 (but they are text, not integers). If the
> >user enters 3 for example, I want a "0" appended to the front. In other
> >words the underlying table will always be from 00 to 99 whether the user
> >enters 1 digit or 2.
> >
> >I don't want the value to just 'look' like "03" for example, but I need
> >there to actually be "03" in the WorkCode field in my underlying table.
> >
> >If it's not too much to ask from the experts I'd like to know how to do this
> >with Input Mask or Format if possible, but I'd also like to learn how to do
> >it using VBA. very many thanks
> >
> >Terrance
>
> You could use an inputmask of
>
> 90
>
> to force entry of only digits, but allow one or two to be entered; then in the
> textbox's AfterUpdate event put code like
>
> Private Sub txWorkCode_AfterUpdate()
> If Len(Me!txWorkCode) < 2 Then
> Me!txWorkCode = Right("00" & Me!txWorkCode, 2)
> End If
> End Sub
>
> One suggestion: if there is a limited number of work codes, why not give the
> user a Combo Box showing the list, and letting them just select one? This
> could even allow you to show a human-meaningful translation rather than just
> two digits.
> --
>
> John W. Vinson [MVP]
> .
>
From: DrGUI on
....or you can try the following:

Private Sub txWorkCode_AfterUpdate()
Me.txWorkCode.value = format(Me.txWorkCode.value, "00")
End Sub

"terry w" wrote:

> hi experts - I am quite new to this. I have a txtbox on my bound form called
> txWorkCode. It is a required field and duplicates are not allowed. I want
> it to accept only digits 0 to 9 (but they are text, not integers). If the
> user enters 3 for example, I want a "0" appended to the front. In other
> words the underlying table will always be from 00 to 99 whether the user
> enters 1 digit or 2.
>
> I don't want the value to just 'look' like "03" for example, but I need
> there to actually be "03" in the WorkCode field in my underlying table.
>
> If it's not too much to ask from the experts I'd like to know how to do this
> with Input Mask or Format if possible, but I'd also like to learn how to do
> it using VBA. very many thanks
>
> Terrance