Moving Data in a Recordset from One List Box to Another

  • Thread starter bfuenz via AccessMonster.com
  • Start date
B

bfuenz via AccessMonster.com

I created a database that gives me the names of all the tables in Access
including the Sys tables. I also created code to remove the Sys tables and
to show me only the user created tables. All of this happens on a click and
the data is brought into a List box. The list box is populated not through a
table or query but by the rowsource being filled out through a str SQL
procedure. The code looks like this:

***

Private Sub cmdListTables_Click()

Dim db As Database
Dim varstr As String
Dim tdfLoop As TableDef
Dim i As Integer

Set db = CurrentDb()

With db

For Each tdfLoop In .TableDefs
varstr = varstr & tdfLoop.Name & ", "
Next tdfLoop

End With

Me.List0.RowSourceType = "Value List"

Select Case Me.List0.RowSource = varstr

Case Is = Me.List0.RowSource = "MSysAccesObjects, MSysAccessXML,
MSysAces, MSysNavPaneGroupCategories, MSysNavPaneGroups,
MSysNavPaneGroupToObjects, MSysNavPaneObjectIDS, Objects, Queries,
Relationships"

Me.List0.RowSourceType = "Table/Query"

Me.List0.RowSource = "SELECT MSysObjects.Name FROM MSysObjects WHERE ((
(Left([Name],4))<>'MSys') AND ((MSysObjects.Type)=1)) ORDER BY MSysObjects.
Name;"

End Select

End Sub

***

What I want to do now is use that populated Listbox (List0) and have the user
select one or many of the records and have it (the selected records) move to
another list box. I want to this without having to create a table or query.
Is that possible? Any help would be appreciated.
 
C

Carl Rapson

Use the ItemsSelected collection of the listbox:

Dim vnt as Variant
For Each vnt in List0.ItemsSelected
List1.AddItem listbox.ItemData(vnt)
Next vnt

The RowSourceType of List1 will need to be Value List for this to work.

Carl Rapson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top