Access Database Tip: How to Multiselect in a Listbox

By: Jon Watson

Access Database Tip: How do I multi select in a List box?

When you have a list box it is handy to be able to multiselect to perform some action on multiple items in the list box. Here is a simple set of instructions to get you started. These instructions will create a quick way to multiselect and delete rows from a table.

Follow these steps:

1]create a simple form

2]add two text boxes named SelCt and LstCt

3]add a list box named List0

4]on the list box properties form tab "Other" set the Multi Select to Extended

5]on the "Data" tab set

Rowsource type to Table/query

row source to SELECT tmpIndextbl.sFileName FROM tmpIndextbl ORDER BY tmpIndextbl.sFileName;

6]put this code between the *****on the "Event" tab "After update" event

**********

Private Sub List0_AfterUpdate()

Dim ctl As Control, X As Integer, selItem As Variant, sql As String

Set ctl = List0

For Each selItem In ctl.ItemsSelected

X = X + 1

Debug.Print ctl.ItemData(selItem)

sql = "DELETE tmpIndextbl.sFileName FROM tmpIndextbl"

sql = sql & " WHERE (((tmpIndextbl.sFileName)='" & ctl.ItemData(selItem) & "'));"

DoCmd.RunSQL (sql)

Next selItem

SelCt = X

List0.Requery

**********

Save the form

7]Create a table with data for this example named "Tmpindextbl. " Make sure you have at least one field named sFileName.

You will need to add some dummy data for testing.

You can download the example and the demo mdb that accompanies this tip at. Getting the example there will save you a little work. The demo database also has a counter to show you how many entries have been selected.



BioMation Systems, Inc provides process improvement services that include solutions used by both large and small companies that are affordable and easy to use. Our products and services are proven to enable our customers to provide better service to their customers while saving them money in the process. Our customers find that their return on investment is most often realized after using their applications just a few times.

What could BioMation Systems do for you?

Go ahead, take a look.

Top Searches on
Technology
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 

» More on Technology
 



Share this article :
Click to see more related articles