I have a rather large unbound form with many combo boxes and text boxes for
data entry and then a command button to execute validation and entry into a
backend database.
Is there one command that I can run at the end of a successful insert that
will clear the entire form of any values that are default values of the
form?
TIA,
Randy
In the Tag property of each control that needs to be cleared put "ClearMe" (it
can be anything). Then use this code to loop the controls in the form and clear
them.
Dim ctl As Control
For Each ctl in Me.Controls
If ctl.Tag = "ClearMe" Then ctl.Value = Null
Next ctl
if Not (ctl Is Nothing) Then Set ctl = Nothing
If there is more work to do than just clearing the controls (enabling/disabling
controls, setting backcolors etc) you can add these into the loop by using
different Tags and using a Select Case in the above loop.
If there are a lot of controls to work on, it is sometimes easier and quicker
(especially with unbound forms) to simply close and reopen the form.
Dim strFrmName As String
strFrmName = Me.Name
On Error Resume Next
Application.Echo False
DoCmd.Close acForm, strFrmName
DoCmd.OpenForm strFrmName
Application.Echo True
On Error GoTo 0
Wayne Gillespie
Gosford NSW Australia