mcnewsxp said:
how does one clear a listbox in access 2003?
lbxMyBox.clear don't do it.
You can try simply setting the listbox's value to "Null" if "MultiSelect" is set
to "None":
Me.lbxMyBox.Value = Null
If "MultiSelect" is set to "Simple" or "Extended, you can cycle through each
selected row and set its "Selected" property to false. You can use the following
function to do this:
'************FUNCTION START********
Public Function fncClearListBox(ctl As ListBox)
' Comments : Clears selected rows from multiselect listbox
' Parameters: ctl - A reference to the listbox to clear
' Returns : <none>
' Created : 11/30/04 14:02 Bruce M. Thompson
' Modified :
' Usage : fncClearListBox Forms("frmTest").lstListBoxName
' ... or, if called from within the form containing the listbox ...
' fncClearListBox Me.lstListBoxName
' --------------------------------------------------
On Error GoTo fncClearListBox_ERR
'Declare variables
Dim varItem As Variant
'Unselect the selected rows
For Each varItem In ctl.ItemsSelected
ctl.Selected(varItem) = False
Next
fncClearListBox_EXIT:
Exit Function
fncClearListBox_ERR:
MsgBox "Error " & Err.Number & " occurred in fncClearListBox: " &
Err.Description
Resume 'fncClearListBox_EXIT
End Function
'************FUNCTION END**********
Copy the function to a standard module (a global module, not a module behind a
form or report) and call it using the same syntax used in the examples provided
in the function's comments section.