I am using the following public subprocedure to reset all UserForm controls
I am using a dynamic userform where a frame frmModifyTemplate is dynamically filled with textbox controls from a range in Excel
Code in the Userform AddMethodToTemplate for reset button goes like this
It works. However, I have to click twice for it to work. First time, it clears only the first textbox control, but not all. Please guide how I can change the code to make the reset all button work in first click only.
VBA Code:
Public Sub ResetUserFormControls(FormName As UserForm)
Dim Ctrl As MSForms.Control
For Each Ctrl In FormName.Controls
If (TypeName(Ctrl) = "TextBox") Or (TypeName(Ctrl) = "ListBox") Then
Ctrl.Value = ""
End If
Next Ctrl
End Sub
Code in the Userform AddMethodToTemplate for reset button goes like this
VBA Code:
Private Sub btnReset_Click()
' Reset values on the USERFORM by calling ResetUserFormControls public subprocedure present in _
CalledPublicProcedures
Call ResetUserFormControls(AddMethodToTemplate)
End Sub
It works. However, I have to click twice for it to work. First time, it clears only the first textbox control, but not all. Please guide how I can change the code to make the reset all button work in first click only.