Access Database Tip: How to multiselect in a Listbox

These instructions will create a quick way to multiselect and delete rows from a table.

by Jon Watson

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

When you have a list box it is hand to be able to multiselet 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. http://www.biomationsystems.com/AccessTips.htm

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.

About the Author

Jon Watson is the founder of Biomation Systems, Inc. With 26 years experience helping Fortune 500 companies with process improvement he formed BioMation to bring the same expertise to smaller companies that need the same improvements at an affordable price.

Tell others about
this page:

facebook twitter reddit google+



Comments? Questions? Email Here

© HowtoAdvice.com

Next
Send us Feedback about HowtoAdvice.com
--
How to Advice .com
Charity
  1. Uncensored Trump
  2. Addiction Recovery
  3. Hospice Foundation
  4. Flat Earth Awareness
  5. Oil Painting Prints