How to make a TextBox fill up the space with zero?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a bound TextBox to let the user key in up to 7 digits to store in the table as TEXT type. If the user keys in 6 digits, I want it be able to add one “0†in front of the 6 digits automatically and store all the 7 digits in the table as TEXT type. How can I do it? Your help will be appreciated.
 
Use the Format() function to add the leading zeros.

Assuming a text box named "Text1", set its AfterUpdate property to:
[Event Procecdure]

Click the Build button (...) beside this, and enter this code:

Private Sub Text1_AfterUpdate()
If Len(Me.Text1) < 7 Then
Me.Text1 = Format(Me.tb, "0000000")
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Jeff said:
I have a bound TextBox to let the user key in up to 7 digits to store in
the table as TEXT type. If the user keys in 6 digits, I want it be able to
add one "0" in front of the 6 digits automatically and store all the 7
digits in the table as TEXT type. How can I do it? Your help will be
appreciated.
 
Jeff said:
I have a bound TextBox to let the user key in up to 7 digits to store in the table as TEXT type. If the user keys in 6 digits, I want it be able to add one “0” in front of the 6 digits automatically and store all the 7 digits in the table as TEXT type. How can I do it? Your help will be appreciated.


Use a line of code in the text box's AfterUpdate event
procedure to supply the extra zeros:

thetextbox = Right("000000" & thetextbox, 7)
 
Back
Top