• Initializing a form… (Word 97)

    Author
    Topic
    #380012

    I have a user form with initialized values:
    txtNumRows.Text = 2
    txtNumCol.Text = 2

    When the user click the macro button and receives the user form, the values are appropriately populated, but I would like them to be highlighted/Selected, so that they don’t have to backspace to alter the value. I can’t seem to find the property that will do that…. Help Please…..

    Viewing 0 reply threads
    Author
    Replies
    • #634716

      Well,

      Since they are two separate text boxes, you can’t select both. You can only select one.

      txtNumRows.SelStart = 0
      txtNumRows.SelLen = len(txtNumRows.Text)

      However, it you put that code in the GotFocus event of the Text box, the value will be selected whenever the text box receives the focus.

      • #634717

        Worked like a charm! Thanks!

        Private Sub UserForm_Initialize()
        ‘Set row value to 2
        txtNumRows.Text = 2
        txtNumRows.SelStart = 0
        txtNumRows.SelLength = Len(txtNumRows.Text)

        ‘Set Column value to 2
        txtNumCol.Text = 2
        txtNumCol.SelStart = 0
        txtNumCol.SelLength = Len(txtNumCol.Text)
        End Sub

        • #634718

          Ooops….
          When the user form comes up, the value was 2 (highlighted). I press 6 and the number 66 appears?
          When I tab and alter the second value, no problem….. what’s up?

          • #634722

            I found it,
            In my playing/testing, I had dropped the line of code that was carrying over:

            Private Sub txtNumRows_Change()
            txtNumRows.SelText = txtNumRows.Text
            txtNumRows.SelLength = Len(txtNumRows.Text)
            End Sub

    Viewing 0 reply threads
    Reply To: Initializing a form… (Word 97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: