Generic code to select or deselect all is noted below. To call this from
code in your form, use something like:
Private Sub cmdClearLender_Click()
ClearListBox Me.lboLenderEmpID
End Sub
Sub SelectListBox(pctlListBox As ListBox)
'============================================================
' Purpose: select all selection from a list box control
' Called From: Multiple
' Date: 2/21/2003
' Parameters: list box object
'============================================================
On Error GoTo SelectListBox_Error
Dim intListCount As Integer
Dim intItem As Integer
intListCount = pctlListBox.ListCount
For intItem = 0 To intListCount - 1
pctlListBox.Selected(intItem) = True
Next
ExitSelectListBox:
On Error Resume Next
Exit Sub
SelectListBox_Error:
Select Case Err
Case Else
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure SelectListBox of Module basControlProcedures"
End Select
Resume ExitSelectListBox:
End Sub
Sub ClearListBox(pctlListBox As ListBox)
'============================================================
' Purpose: clear all selection from a list box control
' 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