Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / September 2005

Tip: Looking for answers? Try searching our database.

How To Clear Off List Box With VBA Code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
doyle60@aol.com - 23 Sep 2005 02:49 GMT
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
Marshall Barton - 23 Sep 2005 03:18 GMT
>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]

Duane Hookom - 23 Sep 2005 03:19 GMT
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
Thanks.  It worked.

Matt
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]

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.