Visual Basic Form

  • Thread starter Thread starter Carrie_Loos via OfficeKB.com
  • Start date Start date
C

Carrie_Loos via OfficeKB.com

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
 
Do you hide the userform and then show it?

If yes, try unloading and then loading it.
 
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
 
This works well - Thanks
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top