VBA: Showing a text string in a text box

  • I have a text box on a userform where I want to write strings starting with 0.

    At present, if I type in this number "00011" the displayed output will be "11" - the zeros are ignored.

    What do I have to do in my code to be able to display the all strings beginning with "0".

    Do I have to use the Afterupdate event, or the Change event to make this happen or to I have to include the code in the form Initialize event.


  • Hi,

    Sorry, I can't reproduce your problem. I created a new userform and added a textbox and a commandbutton. The code for the button is below:

    Private Sub CommandButton1_Click()
    MsgBox TextBox1.Value
    Unload Me
    End Sub

    If I display the form and enter "00011" in the textbox and then press the commandbutton the messagebox displays "00011".

    Could you attach an example of the offending workbook?

  • A textbox should take the input as text and remember the leading 000. Are you sure the 000 are not being lost after you have retrieved the textbox text? What do you then do with the input string?

  • that's what I thought, but it isn't remember the 000, it is automatically changing it to "" before I type in the next number.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!