ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Visual Basic Form (https://www.excelbanter.com/excel-programming/404772-visual-basic-form.html)

Carrie_Loos via OfficeKB.com

Visual Basic Form
 
Can anyone tell me how to clear a form? When I first pull my form up, which
has radio buttons with code, the buttons are clear but after I make a choice
and pull it up again button is still indicated. I have to close the form and
re-open it once again to clear. What am I not doing correctly?

Thx

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200801/1


Dave Peterson

Visual Basic Form
 
Do you hide the userform and then show it?

If yes, try unloading and then loading it.



"Carrie_Loos via OfficeKB.com" wrote:

Can anyone tell me how to clear a form? When I first pull my form up, which
has radio buttons with code, the buttons are clear but after I make a choice
and pull it up again button is still indicated. I have to close the form and
re-open it once again to clear. What am I not doing correctly?

Thx

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200801/1


--

Dave Peterson

Alpineman2

Visual Basic Form
 
Try this: should work for both textbox & optionbutton

Private Sub CommandButton1_Click()
' Clear the form
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is MSForms.TextBox Then
ctrl.Value = ""
ElseIf TypeOf ctrl Is MSForms.OptionButton Then
ctrl.Value = False
End If
Next ctrl
End Sub

"Carrie_Loos via OfficeKB.com" wrote:

Can anyone tell me how to clear a form? When I first pull my form up, which
has radio buttons with code, the buttons are clear but after I make a choice
and pull it up again button is still indicated. I have to close the form and
re-open it once again to clear. What am I not doing correctly?

Thx

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200801/1



Carrie_Loos via OfficeKB.com

Visual Basic Form
 
This works well - Thanks

Alpineman2 wrote:
Try this: should work for both textbox & optionbutton

Private Sub CommandButton1_Click()
' Clear the form
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is MSForms.TextBox Then
ctrl.Value = ""
ElseIf TypeOf ctrl Is MSForms.OptionButton Then
ctrl.Value = False
End If
Next ctrl
End Sub

Can anyone tell me how to clear a form? When I first pull my form up, which
has radio buttons with code, the buttons are clear but after I make a choice
and pull it up again button is still indicated. I have to close the form and
re-open it once again to clear. What am I not doing correctly?

Thx


--
Message posted via http://www.officekb.com



All times are GMT +1. The time now is 06:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com