User forms "Clear"

G

Guest

Hello,
I have a bunch of user forms with in a workbook. I have a button on sheet1
that is to clear the check boxes, list boxes..etc...of all the user forms,
but the code I have below only works some of the time clearing all the forms.
other times I have to click the clear button on sheet one several times to
get all the user forms to clear. Can anyone please take a look at the below
code and let me know what I'm doing worng/missing.

greatful for any help.... Lime
Private Sub cmdbtnnextcase_Click()

Dim smessage As String
smessage = "Are you sure you want to Start a New Case?" + " All
information will be cleared."
If MsgBox(smessage, vbQuestion + vbYesNo, _
"Start a New Case") = vbYes Then

For Each ctrl In frmBackPain.Controls
If TypeName(ctrl) = "CheckBox" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "OptionButton" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "TextBox" Then
ctrl.Value = ""
ElseIf TypeName(ctrl) = "ComboBox" Then
ctrl.Value = ""
ElseIf TypeName(ctrl) = "ListBox" Then
ctrl.Value = ""
End If
Next ctrl

For Each ctrl In frmCADMI.Controls
If TypeName(ctrl) = "CheckBox" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "OptionButton" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "TextBox" Then
ctrl.Value = ""
ElseIf TypeName(ctrl) = "ComboBox" Then
ctrl.Value = ""
ElseIf TypeName(ctrl) = "ListBox" Then
ctrl.Value = ""
End If
Next ctrl

For Each ctrl In frmCOPD.Controls
If TypeName(ctrl) = "CheckBox" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "OptionButton" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "TextBox" Then
ctrl.Value = ""
ElseIf TypeName(ctrl) = "ComboBox" Then
ctrl.Value = ""
ElseIf TypeName(ctrl) = "ListBox" Then
ctrl.Value = ""
End If
Next ctrl

For Each ctrl In frmcva.Controls
If TypeName(ctrl) = "CheckBox" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "OptionButton" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "TextBox" Then
ctrl.Value = ""
ElseIf TypeName(ctrl) = "ComboBox" Then
ctrl.Value = ""
ElseIf TypeName(ctrl) = "ListBox" Then
ctrl.Value = ""
End If

Next ctrl

For Each ctrl In frmesrdckd.Controls
If TypeName(ctrl) = "CheckBox" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "OptionButton" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "TextBox" Then
ctrl.Value = ""
ElseIf TypeName(ctrl) = "ComboBox" Then
ctrl.Value = ""
ElseIf TypeName(ctrl) = "ListBox" Then
ctrl.Value = ""
End If
Next ctrl

For Each ctrl In frmGenMed.Controls
If TypeName(ctrl) = "CheckBox" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "OptionButton" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "TextBox" Then
ctrl.Value = ""
ElseIf TypeName(ctrl) = "ComboBox" Then
ctrl.Value = ""
ElseIf TypeName(ctrl) = "ListBox" Then
ctrl.Value = ""
End If
Next ctrl

For Each ctrl In frmHeartFailure.Controls
If TypeName(ctrl) = "CheckBox" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "OptionButton" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "TextBox" Then
ctrl.Value = ""
ElseIf TypeName(ctrl) = "ComboBox" Then
ctrl.Value = ""
ElseIf TypeName(ctrl) = "ListBox" Then
ctrl.Value = ""
End If
Next ctrl

For Each ctrl In usrfrmhighriskcriteria.Controls
If TypeName(ctrl) = "OptionButton" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "CheckBox" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "TextBox" Then
ctrl.Value = ""
ElseIf TypeName(ctrl) = "ComboBox" Then
ctrl.Value = ""
ElseIf TypeName(ctrl) = "ListBox" Then
ctrl.Value = ""
End If

Next ctrl


For Each ctrl In frmpancreatitis.Controls
If TypeName(ctrl) = "CheckBox" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "OptionButton" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "TextBox" Then
ctrl.Value = ""
ElseIf TypeName(ctrl) = "ComboBox" Then
ctrl.Value = ""
ElseIf TypeName(ctrl) = "ListBox" Then
ctrl.Value = ""
End If
Next ctrl


For Each ctrl In usrfrmsavingscalc.Controls
If TypeName(ctrl) = "CheckBox" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "OptionButton" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "TextBox" Then
ctrl.Value = ""
ElseIf TypeName(ctrl) = "ComboBox" Then
ctrl.Value = ""
ElseIf TypeName(ctrl) = "ListBox" Then
ctrl.Value = ""
End If

Next ctrl

For Each ctrl In usrfrmprofile.Controls
If TypeName(ctrl) = "CheckBox" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "OptionButton" Then
ctrl.Value = False
ElseIf TypeName(ctrl) = "TextBox" Then
ctrl.Value = ""
ElseIf TypeName(ctrl) = "ComboBox" Then
ctrl.Value = ""
End If
Next ctrl


Sheet3.Range("N2:N3") = ""
Sheet3.Range("H19:H21") = ""
usrfrmprofile.cmbobxprofilelinquistic = "English"

Sheet1.Range("C5") = "Select Condition"
ckbxinfoby = "Member"
Sheet1.Range("A12") = ""
Sheet1.Range("A7:G8") = ""
Sheet1.Range("A9:G10") = ""
Sheet3.Range("A93") = ""
Sheet3.Range("N2:N3") = ""
Sheet3.Range("X2:X10") = ""
Sheet3.Range("K1:K14") = ""
Sheet3.Range("AD12:AF12") = ""
Sheet3.Range("AD2:AE7") = ""
usrfrmprofile.Show
End If

End Sub
 
L

Luis Fernando Ortiz M.

Hi,

Try this: Unload and Show the UserForm at the same Sub, this procedure clean
all controls in the UserForm

Regards,

Fernando Ortiz
 
G

Guest

Hi,
I'm sorry but I do not understand? Can you give a little exsample to get
started?

Lime
 
S

Susan

what he means is:

Private Sub cmdbtnnextcase_Click()


Dim smessage As String
smessage = "Are you sure you want to Start a New Case?" + " All
information will be cleared."
If MsgBox(smessage, vbQuestion + vbYesNo, _
"Start a New Case") = vbYes Then


unload me
load userform1
userform1.show
end if

end sub

unloading & reloading the sub will clear the form. OR, this is what i
do. in my userform_initialization sub i have everything set to open
with nothing in the boxes & ranges, etc. so when i want to clear the
form, i have it call the initialization sub & basically "reset" the
form.

Private Sub cmdbtnnextcase_Click()


Dim smessage As String
smessage = "Are you sure you want to Start a New Case?" + " All
information will be cleared."
If MsgBox(smessage, vbQuestion + vbYesNo, _
"Start a New Case") = vbYes Then
call userform_initialization
end if
end sub

hope it helps!
susan
 
G

Guest

Thanks but I have multipal forms in one workbook that all need to be cleared
as one time.
 
S

Susan

Thanks but I have multipal forms in one workbook that all need to be cleared
as one time.

sub clear_multiple()
call userform1_initialize
call userform2_initialize
call userform3_initialize
end sub

should work
susan
 

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

Top