Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

clear all text/combo boxes with one click 1

Status
Not open for further replies.

newprogamer

Programmer
Sep 22, 2004
107
US
Hello,

Is there a way to clear all the text boxes/ combo boxes at once. Currently, when I click the clear button it only clears one combo box/ text box. I have to click the clear box once for every box I want to clear. I thought it would clear everything with one click. Is there a way to do this? Any help would be greatly appreciated. My code is below.

Private Sub cmdClearGeneral_Click()
ComboBox1.Text = ""
ComboBox2.Text = ""
ComboBox3.Text = ""
ComboBox4.Text = ""
ComboBox5.Text = ""
ComboBox6.Text = ""
End Sub

Thanks,
NewProgrammer
 
You may try something like this:
ComboBox1.Value = Null
ComboBox2.Value = Null
...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 

Loomah.
ComboBox1.Clear does not work either. I get a run time error. I would like to be able to clear the text that the user has keyed in when the user clicks the 'clear button'. The comboboxes have been created at design time.
 
Textboxes and comboboxes are not the same.

For text boxes:

textbox1.value = ""

For comboboxes:

combobox1.clear
 
Sorry, they are all combo boxes. Below is the things I have tried. I appreciate any help!

.clear did not work at all. There was no error message but it didn't clear the text in the combobox either.
ComboBox22.Clear

.Value cleared the contents but it only cleared one combo box for each time I clicked the clear button.
ComboBox18.Value = ""

.Text cleared the contents but it only cleared one combo box for each time I clicked the clear button. It did the same as .value.
ComboBox18.Text = ""

 
Are the other combo bounded ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I set up a procedure that clears the combo box values and it works well (this is on an Access form that I created:

Private Sub cmdclear_Click()

Combo13 = ""
Combo15 = ""

End Sub

It probably goes without saying, but "cmdclear" is the name of the command button, and Combo13 / Combo15 is the name of the 2 combo boxes it clears out.

I also set it up so that when the user makes a selection and then re-clicks on the first combo box, it clears the values:

Private Sub Combo13_GotFocus()

Combo13 = ""
Combo15 = ""

End Sub

Hope it works.

Richard
 
Sorry I haven't responded, I have been on vacation.

PHV, nothing is bounded.

RichardOneil, I tried your way. It does clear the text typed in by the user. But, I still have the same problem. It only clears one combo box for each time I click the clear button.

I used the VB editor to create the form. The form has several sheet tabs and on each sheet there are several frames. The frames contain combo boxes. Most of the combo boxes are set to fmShowDropButtonWhenNever.
 
I have the data that the user entered being placed in the excel spreadsheet. The combo boxes have a controlsource property set to point to a cell in excel, i.e General!B7. When I remove the controlsource then the clear button is able to clear everything on the sheet with one click.

The controlsource is set because I need to be able to save the information entered by the customer into a spreadsheet.

Is this normal? Is there another way to save information without the controlsource affecting the clear button?
 
To clear the combo have you tried to clear the referenced cell ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Something like this:
Sheets("General").Range("B7") = ""

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks so much for your help. I have learned that if the combo box is bound to a cell then you must clear the referenced cell. By bound, I mean a cell in the spreadsheet will equal the value in the combo box. For example, ControlSource = General!B3

Here is what works when the cell bound . . .
Sheets("General").Range("B7") = "" (Thanks PHV)
or
Sheets("General").Cells(7, "B").Value = ""

Here is what works when the cell is not bound...
textbox1 = ""
TextBox1.Value = "" (Thanks mintjulep)
combobox1 = "" (Thanks RichardOneil)
combobox1.value = ""
ComboBox1.Value = Null (Thanks PHV)

Here is what does not work...
combobox1.clear

A star for PHV!!!!!!!!!
 
Hope I can help you out here....

create a module
Code:
Sub ClearCombo()
Dim Combo As Control

For Each Combo In UserForm1  '<-- name of UserForm
   If TypeOf Combo Is ComboBox Then
      Combo.Text = Empty
   End If
Next
End Sub

Create a CommandButton and enter the following code:

Code:
Private Sub Command1_Click()
   Call ClearCombo
End Sub

---------------------------------------
This will be the day when all of God’s children will be able to sing with a new meaning, “My country, ‘tis of thee, sweet land of liberty, of thee I sing. Land where my fathers died, land of the pilgrim’s pride, from every mountainside, let freedom ring. - Marten Luther King
 
ooops.... made a little mistake...

Code:
Combo.[b]Value[/b] = Empty

---------------------------------------
This will be the day when all of God’s children will be able to sing with a new meaning, “My country, ‘tis of thee, sweet land of liberty, of thee I sing. Land where my fathers died, land of the pilgrim’s pride, from every mountainside, let freedom ring. - Marten Luther King
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top