Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 9 of 9

Thread: Clear Userform Textbox

  1. #1
    Join Date
    26th October 2006
    Posts
    7

    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:

    VB:
    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

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    17th October 2005
    Location
    Brisbane Australia
    Posts
    553

    Re: Clear Userform Textbox

    hi Robin and welcome
    i use this which i found in the forums
    VB:
     '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

    Excel Video Tutorials / Excel Dashboards Reports


  3. #3
    Join Date
    26th October 2006
    Posts
    7

    Re: Clear Userform Textbox

    Thanks alot, I got it working now!

    /Robin

    Excel Video Tutorials / Excel Dashboards Reports


  4. #4
    Join Date
    17th October 2005
    Location
    Brisbane Australia
    Posts
    553

    Re: Clear Userform Textbox

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

    /Robin
    : D : D
    finally got to help someone

    Excel Video Tutorials / Excel Dashboards Reports


  5. #5
    Join Date
    14th July 2004
    Posts
    10,539

    Re: Clear Userform Textbox

    Could you not use the PasswordChar property of the textbox?

    Excel Video Tutorials / Excel Dashboards Reports


  6. #6
    Join Date
    26th October 2006
    Posts
    7

    Re: Clear Userform Textbox

    Quote 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?

    Excel Video Tutorials / Excel Dashboards Reports


  7. #7
    Join Date
    14th July 2004
    Posts
    10,539

    Re: Clear Userform Textbox

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

    Excel Video Tutorials / Excel Dashboards Reports


  8. #8
    Join Date
    26th October 2006
    Posts
    7

    Re: Clear Userform Textbox

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

    Excel Video Tutorials / Excel Dashboards Reports


  9. #9
    Join Date
    24th January 2003
    Location
    Australia
    Posts
    31,705

    Re: Clear Userform Textbox

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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Possible Answers

  1. Replies: 3
    Last Post: May 23rd, 2008, 22:14
  2. Clear All UserForm TextBoxes
    By frenchlulu in forum EXCEL HELP
    Replies: 2
    Last Post: July 18th, 2007, 18:17
  3. Clear Userform
    By iiawak in forum EXCEL HELP
    Replies: 4
    Last Post: April 11th, 2007, 10:53
  4. clear all textboxes on userform
    By rikapple in forum EXCEL HELP
    Replies: 2
    Last Post: December 22nd, 2005, 16:51
  5. How to clear userform controls
    By langel in forum EXCEL HELP
    Replies: 4
    Last Post: July 28th, 2004, 18:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
porno