-
I've been searching through some reference material and have done a number of searches on the forum... But haven't found what I was looking for. :(
I have a cmdClear button on the Form and desire to have all information inputted into the controls wiped clean, if a User happens to want to start over.
Is there a quick, simple, clean way to clear an entire Form and associated Input Boxes???
-
Code:
For Each ctl In If TypeOf ctl Is TextBox Then
ctl.Text=""
End If
Next ctl
This will clear text for all textboxes.
-
Matthew ~
Thanks for the head's up!!! :-)
I was reading up on the Text = "" earlier this afternoon. On my form though, there are also OptionButtons and Input Boxes requesting Yes and No answers with the Values being held by Variables.
The end result will be the information is be dumped into a Database. If a User wants to clear all inputted data, do I need to write code for all Controls and Input Boxes seperately??? Like you did for the Text Boxes??? Or am I missing something simple like possibly a Form.Clear type of thing??? Is there anything like this???
I could be searching for code which doesn't exist! :D
-
found this code at:
http://www.vb-world.net/articles/functions3/index2.html
It requires two parameters - the form you want to clear, plus a pSkipThese string. The code checks pSkipThese and skips over any controls beginning with that string. So if you pass in 'txt' as pSkipThese, it skips all the text boxes (providing the form developer followed standard naming conventions!). Try it!
Public Sub ClearForm(ByRef pForm As Object, _
Optional ByVal pSkipThese As String = "")
Dim Ctl As Control
Dim pSkipLen As Long
On Error Resume Next
pSkipLen = Len(pSkipThese)
For Each Ctl In pForm
If pSkipThese <> "" Then
If Left(Ctl.name, pSkipLen) <> pSkipThese Then
Select Case TypeName(Ctl)
Case "TextBox"
Ctl.Text = ""
Case "CheckBox"
Ctl.Value = vbUnchecked
Case "ComboBox"
Ctl.ListIndex = -1
Ctl.Text = ""
End Select
End If
Else
Select Case TypeName(Ctl)
Case "TextBox"
Ctl.Text = ""
Case "CheckBox"
Ctl.Value = vbUnchecked
Case "ComboBox"
Ctl.ListIndex = -1
Ctl.Text = ""
End Select
End If
Next
End Sub