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?