Search code examples
vbauserform

getting an odd text box error when resetting form?


Using this code (below) to reset all fields within a userform:

Private Sub cmdReset_Click()
Dim iControl As Control
For Each iControl In Me.Controls
    If iControl.Name Like "txt*" Then iControl = vbnullstring
    If iControl.Name Like "cmb*" Then iControl = vbnullstring
Next
End Sub

and I have one text box (one that's converted to a %) that isn't resetting, but showing this:

-nan(ind)00.00%

any idea how to prevent this and clear the textbox?


Solution

  • Private Sub cmdReset_Click()
    Dim iControl As Control
    For Each iControl In Me.Controls
        If iControl.Name Like "txt*" Then iControl = Null
        If iControl.Name Like "cmb*" Then iControl = Null
    Next
    End Sub