What is the VBA code to uncheck a checkbox and deselect a listbox using TypeOf......Is?
I have an unbound form (Access 2000) with comboboxes, textboxes, checkboxes and listboxes. None of the controls have a Row Source. Each combobox and listbox is supplied by their own table or value list.
Controls on the unbound form are selected to determine the needed output. Once the needed controls have been selected, another command button is clicked to fire more code to select the records that match the selected controls.
Before a new output is selected, the 4 control types need to be cleared. The comboboxes and textboxes do clear with the below VBA, which fires when a command button is clicked. A checkbox or listbox returns run time error 2448 'You can't assign a value to this object'
Private Sub cmdClearCtls_Click()
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is ComboBox Or TypeOf ctl Is TextBox Then
ctl.SetFocus
ctl.Text = ""
End If
' If ctl.ControlType = acCheckBox Then
' ctl = False
' End If
' If TypeOf ctl Is ListBox Then
' ctl.SetFocus
' ctl = ""
' End If
' If TypeOf ctl Is CheckBox Then
' ctl.SetFocus
' ctl = False
' End If
Next
End Sub