| Access Database Tip: How do I multi select | | | | "DELETE tmpIndextbl.sFileName FROM |
| in a List box? | | | | tmpIndextbl"sql = sql & " WHERE |
| | | | (((tmpIndextbl.sFileName)='" & |
| When you have a list box it is handy to be | | | | ctl.ItemData(selItem) & "'));" |
| able to multiselect to perform some action on | | | | |
| multiple items in the list box. Here is a | | | | DoCmd.RunSQL (sql) |
| simple set of instructions to get you | | | | |
| started. These instructions will create a | | | | Next selItem |
| quick way to multiselect and delete rows from | | | | |
| a table. | | | | SelCt = X |
| | | | |
| Follow these steps: | | | | List0.Requery |
| | | | |
| 1]create a simple form | | | | ********** |
| | | | |
| 2]add two text boxes named SelCt and LstCt | | | | Save the form |
| | | | |
| 3]add a list box named List0 | | | | 7]Create a table with data for this example |
| | | | named "Tmpindextbl. " Make sure you have at |
| 4]on the list box properties form tab "Other" | | | | least one field named sFileName. |
| set the Multi Select to Extended | | | | |
| | | | You will need to add some dummy data for |
| 5]on the "Data" tab set | | | | testing. |
| | | | |
| Rowsource type to Table/queryrow source to | | | | You can download the example and the demo mdb |
| SELECT tmpIndextbl.sFileName FROM tmpIndextbl | | | | that accompanies this tip at. Getting the |
| ORDER BY tmpIndextbl.sFileName; | | | | example there will save you a little work. |
| | | | The demo database also has a counter to show |
| 6]put this code between the *****on the | | | | you how many entries have been selected. |
| "Event" tab "After update" event | | | | |
| | | | BioMation Systems, Inc provides process |
| ********** | | | | improvement services that include solutions |
| | | | used by both large and small companies that |
| Private Sub List0_AfterUpdate() | | | | are affordable and easy to use. Our products |
| | | | and services are proven to enable our |
| Dim ctl As Control, X As Integer, selItem As | | | | customers to provide better service to their |
| Variant, sql As String | | | | customers while saving them money in the |
| | | | process. Our customers find that their |
| Set ctl = List0 | | | | return on investment is most often realized |
| | | | after using their applications just a few |
| For Each selItem In ctl.ItemsSelected | | | | times. |
| | | | |
| X = X + 1 | | | | What could BioMation Systems do for you? |
| | | | |
| Debug.Print ctl.ItemData(selItem)sql = | | | | Go ahead, take a look. |