Clear data in text boxes / combo boxes

C

Chris

I am a fairly new user of Access. Apologies if this is a simpe issue.

I have a data entry form which has a number of text boxes and combo boxes. I
wish to setup a button (or an After_Update routine in VBA) that when
activated clear all the values that have ALREADY been entered.

i.e. User enters data, but then wants to reset and start again.

Is there a simple way of doing this using VBA? Is there any other way of
doing this?
 
J

Jeff Conrad

in message:
I am a fairly new user of Access. Apologies if this is a simpe issue.

I have a data entry form which has a number of text boxes and combo boxes. I
wish to setup a button (or an After_Update routine in VBA) that when
activated clear all the values that have ALREADY been entered.

i.e. User enters data, but then wants to reset and start again.

Is there a simple way of doing this using VBA? Is there any other way of
doing this?

If this is a bound form a simple Me.Undo line of code behind the command
button should suffice.

If this is an unbound form just use this little bit of code behind the reset
command button:

Private Sub cmdReset_Click()
Dim ctl As Control
On Error Resume Next
For Each ctl In Me.Controls
ctl = ctl.DefaultValue
Next ctl
End Sub
 
C

Chris

Simple, yet brilliant. Ironically I have been using the value property in
"if" statements to control the data entry process (i.e. reading the value),
but never figured to use it to set a value.

Thankyou!
 
T

Tom Wickerath

Here is a function that I use to clear entries on an unbound form, which is
used to build the WHERE clause of a SQL statement on-the-fly (aka Query by
Form or QBF). It demonstrates how to clear selected values from two
listboxes, values typed into one or more textboxes, and how to reset option
buttons in an option group:

Function ClearControls()
On Error GoTo ProcError

'Dim varDummy As Variant
Dim intCurrCat As Integer

'-- First, clear the multi-select list boxes.
For intCurrCat = 0 To Me!lboAircraftTypes.ListCount - 1
Me!lboAircraftTypes.Selected(intCurrCat) = False
Next

For intCurrCat = 0 To Me!lboOriginators.ListCount - 1
Me!lboOriginators.Selected(intCurrCat) = False
Next

'-- Next, clear all text boxes
Me!txtPGNO = Null
Me!txtFDEO = Null
Me!txtDRO = Null
Me!txtTITLE = Null
Me!txtMeasurand = Null
Me!txtATA = Null
Me!txtTWR = Null
Me!cboInstID = Null
Me!txtBegDateEntered = Null
Me!txtEndDateEntered = Null
Me!txtCHG = Null
Me!txtCOINT = Null

'-- Set the Y/N frame to a value that is not assigned to any of the
visible buttons
fraYN.Value = 2

'-- Clear the subform of any results
[subQueryByForm].[Form].[RecordSource] = "SELECT * FROM qryQBF WHERE
FALSE"

'-- Disable the Export to Excel command button
cmdExportToExcel.Enabled = False

ExitProc:
Exit Function
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, , _
"Error in ClearControls event procedure..."
Resume ExitProc
End Function

_________________________________________

:

if you want to clear or reset a combo box try
Me.cboTyp.Value=Null

Chris
_________________________________________

:

I am a fairly new user of Access. Apologies if this is a simpe issue.

I have a data entry form which has a number of text boxes and combo boxes. I
wish to setup a button (or an After_Update routine in VBA) that when
activated clear all the values that have ALREADY been entered.

i.e. User enters data, but then wants to reset and start again.

Is there a simple way of doing this using VBA? Is there any other way of
doing this?
 
Top