PDA

View Full Version : [SOLVED:] Clear all textboxes except 1



Ryanchris
11-13-2019, 11:38 AM
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

Leith Ross
11-13-2019, 01:01 PM
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

Ryanchris
11-13-2019, 01:12 PM
That makes sense. Thank you!!! I tried it and it works perfectly. Really appreciate your help!

Leith Ross
11-13-2019, 01:22 PM
Hello Ryanchris,

You're welcome. Glad I could help.