>How do you clear a list box with VBA code? That is, if the user has
>blackened in items, how do I clear them off so nothing is chosen?
For a single select list box, set its value to Null.
I seem to remember that multi select list boxes are
troublesome. Try setting it Row source to itself:
Me.listbox.RowSource = Me.listbox.RowSource

Signature
Marsh
MVP [MS Access]
Add this code to a standard module and call it from code in your form like:
ClearListBox Me.lboDepts
Sub ClearListBox(pctlListBox As ListBox)
'============================================================
' Purpose: clear all selection from a list box control
' Programmer: Duane Hookom
' Called From: Multiple
' Date: 2/21/2003
' Parameters: list box object
'============================================================
On Error GoTo ClearListBox_Err
Dim strErrMsg As String 'For Error Handling
Dim varItem As Variant
For Each varItem In pctlListBox.ItemsSelected
pctlListBox.Selected(varItem) = False
Next
ClearListBox_Exit:
On Error Resume Next
Exit Sub
ClearListBox_Err:
Select Case Err
Case Else
strErrMsg = strErrMsg & "Error #: " & Format$(Err.Number) &
vbCrLf
strErrMsg = strErrMsg & "Error Description: " & Err.Description
MsgBox strErrMsg, vbInformation, "ClearListBox"
Resume ClearListBox_Exit
End Select
End Sub

Signature
Duane Hookom
MS Access MVP
> How do you clear a list box with VBA code? That is, if the user has
> blackened in items, how do I clear them off so nothing is chosen?
>
> Thanks,
>
> Matt
doyle60@aol.com - 23 Sep 2005 15:38 GMT
Marshall Barton - 23 Sep 2005 19:33 GMT
Duane, I seem to remember that there were situations(?)
where that didn't work, probably back in A97.

Signature
Marsh
MVP [MS Access]
>Add this code to a standard module and call it from code in your form like:
>
[quoted text clipped - 30 lines]
> End Select
>End Sub
Duane Hookom - 24 Sep 2005 04:36 GMT
I seem to remember something earlier on also. This function is a staple in
most of my Access applications along with code to build a "where clause" of
selected items etc.

Signature
Duane Hookom
MS Access MVP
> Duane, I seem to remember that there were situations(?)
> where that didn't work, probably back in A97.
[quoted text clipped - 35 lines]
>> End Select
>>End Sub
Marshall Barton - 24 Sep 2005 06:09 GMT
>I seem to remember something earlier on also. This function is a staple in
>most of my Access applications along with code to build a "where clause" of
>selected items etc.
If you haven't seen a problem, would you say that the
problem was fixed?
If so, why weren't we told about it? <gdr>
And, would care to hazard a guess as to when it was fixed?

Signature
Marsh
MVP [MS Access]
Duane Hookom - 24 Sep 2005 16:58 GMT
Maybe the problem was "deprecated".

Signature
Duane Hookom
MS Access MVP
>>I seem to remember something earlier on also. This function is a staple in
>>most of my Access applications along with code to build a "where clause"
[quoted text clipped - 6 lines]
> If so, why weren't we told about it? <gdr>
> And, would care to hazard a guess as to when it was fixed?
Marshall Barton - 24 Sep 2005 17:50 GMT
>Maybe the problem was "deprecated".
LOL
No wonder it wasn't done in public ;-)

Signature
Marsh
MVP [MS Access]