Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


How can I pass items selected from a listbox in Access to table & VB?

VaCatFishVaCatFish Member Posts: 1
I am a new user to Access and Visual Basic. I have a listbox in MS Access called list74. The user can select different items in the list. The list contains different columns each having different names and values (list74 is reading in a querie). I would like to pass the items selected in list74 to a table called messages2. I will then read the items and values back from that table (messages2) and do some analysis. Ive been able to read in a table into access, but the program needs to read in the table's values into Visual Basic. The program needs to recognize the values/words in each of the columns of the table (messages2).

This is what I have so far:

Private Sub cmdCopyItem_Click()
CopySelected Me
End Sub

Public Sub CopySelected(ByRef frm As Form)

Dim ctlSource As Control
Dim ctlDest As Control
Dim strItems As String
Dim intCurrentRow As Integer

Set ctlSource = frm!list74 first listbox
Set ctlDest = frm!list111 second listbox Can I change this to send everything to a table called messages2? Do I need SQL to do this? If so what?

For intCurrentRow = 0 To ctlSource.ListCount - 1
If ctlSource.Selected(intCurrentRow) Then
strItems = strItems & ctlSource.Column(0, _
intCurrentRow) & ";"
End If
Next intCurrentRow

' Reset destination control's RowSource property.
ctlDest.RowSource = ""
ctlDest.RowSource = strItems

Set ctlSource = Nothing
Set ctlDest = Nothing

End Sub

Your help is greatly appreciated

Sign In or Register to comment.