This public procedure can be called by any form to clear and reset controls to their default values, be it text, date, currency etc. This could be a textbox, combo box, list box, whatever. The exceptions are for my use and feel free to omit, add or change. I should mention that I only use unbound forms and if I want to reset some controls to a specific default value, I do it in code behind the form after running this procedure.
Public Function fnResetControls(ByVal objLForm As Form)
On Error Resume Next
Dim objControls As Controls, objControl As Control, lngLoop As Long
With objLForm
If objLForm.Properties("PopUp") = False Then DoCmd.Maximize: DoCmd.MoveSize 0, 0
Set objControls = .Controls
For Each objControl In objControls
With objControl
If .Locked = True Then GoTo SkipEnabled
.Enabled = True
SkipEnabled:
Select Case .ControlType
Case Is = acTextBox
.ForeColor = 0
If Left(.ControlSource, 1) = "=" Then .Requery: GoTo NextControl
Select Case objControl.Format
Case Is = ""
objControl.Value = "": GoTo NextControl
Case Is = "Long date"
objControl.Value = Null: GoTo NextControl
Case Is = ">"
objControl.Value = "": GoTo NextControl
Case Is = "General Number"
objControl.Value = 0: GoTo NextControl
Case Is = "Currency"
objControl.Value = 0: GoTo NextControl
Case Is = "$#,##0.00;($#,##0.00)"
objControl.Value = 0: GoTo NextControl
Case Is = "Standard"
objControl.Value = 0: GoTo NextControl
Case Is = "Percent"
objControl.Value = 0: GoTo NextControl
Case Else
objControl.Value = Null: GoTo NextControl
End Select 'End of .Format
Case Is = acSubform
objControl.Requery: GoTo NextControl
Case Is = acComboBox
objControl.Value = "": GoTo NextControl
Case Is = acListBox
Dim varItem As Variant
With objControl
For Each varItem In objControl.ItemsSelected
objControl.Value = Null
Next varItem
End With
Case Is = acOptionGroup
objControl.Value = False: GoTo NextControl
Case Is = acCheckBox
objControl.Value = False: GoTo NextControl
Case Is = acOptionButton
objControl.Value = False: GoTo NextControl
Case Else
GoTo NextControl
End Select '~ End of .ControlType
End With
NextControl:
Next objControl
End With
End Function