Consulting

Results 1 to 4 of 4

Thread: Clear all textboxes except 1

  1. #1

    Clear all textboxes except 1

    Hi all! Would really appreciate some help. I basically have a "Reset" button but I have one textbox that I'd like to not reset/clear when the button is pushed. I'm a big newbie and just not sure how to do that. Here is the code that I have...thank you in advance for your help!! The Textbox that I need to not clear is labelled "SysNameText"

    Private Sub CommandButton23_Click()
    n = MsgBox("Do not forget to UPLOAD your kit. Are you sure you want to continue?", vbYesNo, "New Config")
    If n = vbYes Then


    Dim ctl As Control


    For Each ctl In PipeKitConfig.Controls
    If TypeName(ctl) = "TextBox" Then
    ctl.Value = ""
    End If

    Next ctl
    For Each ctl In PipeKitConfig.Controls
    If TypeName(ctl) = "ComboBox" Then
    ctl.Value = ""
    End If

    Next ctl


    End If
    End Sub
    Last edited by Ryanchris; 11-13-2019 at 11:43 AM. Reason: add more info

  2. #2
    VBAX Expert Leith Ross's Avatar
    Joined
    Oct 2012
    Location
    San Francisco, California
    Posts
    521
    Location
    Hello Ryanchris,

    Here is an improved version of your macro. This uses a single loop and will not clear the text box "SysNameText".

    Private Sub CommandButton23_Click()
    
    
        Dim n   As Integer
        Dim Ctl As Control
        
            n = MsgBox("Do not forget to UPLOAD your kit. Are you sure you want to continue?", vbYesNo, "New Config")
            If n = vbNo Then Exit Sub
    
    
            For Each Ctl In PipeKitConfig.Controls
                Select Case TypeName(Ctl)
                    Case Is = "TextBox"
                        If Ctl.Name <> "SysNameText" Then Ctl.Value = ""
                    Case Is = "ComboBox"
                        Ctl.Value = ""
                End Select
            Next Ctl
    
    
    End Sub
    Sincerely,
    Leith Ross

    "1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG"

  3. #3
    That makes sense. Thank you!!! I tried it and it works perfectly. Really appreciate your help!

  4. #4
    VBAX Expert Leith Ross's Avatar
    Joined
    Oct 2012
    Location
    San Francisco, California
    Posts
    521
    Location
    Hello Ryanchris,

    You're welcome. Glad I could help.
    Sincerely,
    Leith Ross

    "1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG"

Tags for this Thread

Posting Permissions

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