The basic idea is to loop through all controls on your form, and set the
Value to Null.
Of course, that applies only to controls that have a Value and are unbound.
There's an example below. Replace the call to the error logger with your own
handler, or use the one at:
http://allenbrowne.com/ser-23a.html
Note that toggle buttons, check boxes, and option buttons do have a
ControlSource and Value, but not if they are part of an option group.
-----------------------code starts--------------------------
Private Sub cmdReset_Click()
On Error GoTo Err_cmdReset_Click
'Purpose: Restore to the state when first loaded.
Dim ctl As Control
For Each ctl In Me.Controls
Select Case ctl.ControlType
Case acTextBox 'Reset text boxes to blank.
If Not IsNull(ctl.Value) Then
If Left(ctl.ControlSource, 1) = "=" Then
'do nothing
Else
ctl.Value = Null
End If
End If
Case acComboBox, acOptionGroup, acCheckBox 'Reset to default
value.
If Nz(ctl.DefaultValue, "") <> vbNullString Then
ctl.Value = ctl.DefaultValue
ElseIf Not IsNull(ctl.Value) Then
ctl.Value = Null
End If
Case acListBox 'Unselect everything in
listboxes.
Call ClearList(ctl)
Case acLabel, acCommandButton, acOptionButton, acTabCtl, acPage,
acRectangle, acLine, acImage, acBoundObjectFrame, acSubform, acObjectFrame,
acPageBreak, acCustomControl
'Do nothing
Case Else
Debug.Print ctl.Name & " not handled"
End Select
Next
Exit_cmdReset_Click:
Exit Sub
Err_cmdReset_Click:
Call LogError(Err.Number, Err.Description, conMod & ".cmdReset_Click")
Resume Exit_cmdReset_Click
End Sub
Function ClearList(lst As ListBox) As Boolean
On Error GoTo Err_ClearList
'Purpose: Unselect all items in the listbox.
'Return: True if successful
Dim varItem As Variant
If lst.MultiSelect = 0 Then
lst = Null
Else
For Each varItem In lst.ItemsSelected
lst.Selected(varItem) = False
Next
End If
ClearList = True
Exit_ClearList:
Exit Function
Err_ClearList:
Call LogError(Err.Number, Err.Description, conMod & ".ClearList")
Resume Exit_ClearList
End Function
-----------------------code ends--------------------------