text box help needed

T

terry w

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
 
J

John W. Vinson

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.
 
T

terry w

John - thanks! I'll take your advice.

John W. Vinson said:
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.
 
D

DrGUI

....or you can try the following:

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top