Clearing form's data

  • Thread starter Thread starter Randy K.
  • Start date Start date
R

Randy K.

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
 
Hi,

I don't know if there is a one command that'll accomplish
what you want, but here's something that works:

----------------------------------
Dim ctrl As Control

For Each ctrl on Me.Controls
If ctrl.ControlType = acTextBox Or ctrl.ControlType
= acComboBox Then
ctrl = Null
End If
Next ctrl
 
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
 
Back
Top