Announcement

Collapse
No announcement yet.

Clear Userform Textbox

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Clear Userform Textbox

    Hi everbody,

    This is my first post here, so I'll try my absolute best to comply with the rules and so forth

    So, about my problem. In my workbook, I have several sheets, and all of them except two are set to xlSheetVeryHidden. On Sheet1, there is a button that starts a UserForm. In this form, users can enter their own password which then changes the visibility of "their" sheet to .Visible.

    However, if the workbook is left open, and another user clicks the button to open the UserForm, the last entered password is still in the TextBox.

    So, my question is; How do I clear the textBox using VBA-code?

    Here is the VB-code for the commandbutton in UserForm1:

    Code:
    Private Sub CommandButton1_Click()
    
    If msg = vbNullString Then 'Cancelled
            Blad1.Select
            UserForm1.Hide
    Exit Sub
    End If
    
    'User1
    If msg = "User1" Then
    Blad3.Visible = xlSheetVisible
    Blad3.Select
    UserForm1.Hide
    End If
    
    End Sub
    I hope you understand what Im trying to accomplish here

    Thanks
    Robin

  • #2
    Re: Clear Userform Textbox

    hi Robin and welcome
    i use this which i found in the forums
    Code:
    'CLEARS ALL CONTROLS
    'http://www.ozgrid.com/forum/showthread.php?t=44070&highlight=CLEAR+controls
    Dim Ctrl As Control
    For Each Ctrl In Me.Controls
        If TypeOf Ctrl Is MSForms.ComboBox Then
            Ctrl.Text = ""
        End If
    Next Ctrl
    For Each Ctrl In Me.Controls
        If TypeName(Ctrl) = "TextBox" Then
            Ctrl.Text = ""
        End If
    Next Ctrl
    cheers
    toe

    Comment


    • #3
      Re: Clear Userform Textbox

      Thanks alot, I got it working now!

      /Robin

      Comment


      • #4
        Re: Clear Userform Textbox

        Originally posted by xplejjn
        Thanks alot, I got it working now!

        /Robin
        : D : D
        finally got to help someone

        Comment


        • #5
          Re: Clear Userform Textbox

          Could you not use the PasswordChar property of the textbox?
          Boo!

          Comment


          • #6
            Re: Clear Userform Textbox

            Originally posted by norie
            Could you not use the PasswordChar property of the textbox?
            I am using the PasswordChar, however, when the next user opens the UserForm, the password from the user before him, although only shown as "*****", still works if the user just use the OK button.

            Did that make any sense?

            Comment


            • #7
              Re: Clear Userform Textbox

              Why don't you unload the userform rather than just hiding it?
              Boo!

              Comment


              • #8
                Re: Clear Userform Textbox

                Originally posted by norie
                Why don't you unload the userform rather than just hiding it?
                For some reason, I hadn't thought of that. Thanks.

                Comment


                • #9
                  Re: Clear Userform Textbox

                  Yes, the normal way is like
                  Code:
                  Unload Me
                  UserForm1.Show

                  Comment

                  Working...
                  X