G
Guest
Below I took the example from Helen Feddema. What I accomplished was a
playlist to play MP3's and the below code works.
However, I wanted to store the records under someones name. So what I did
was added a field to the TPlaylistSelect table called personsname. I also
made another table called TNAMES to store the persons name who wants to make
the playlist. So on my form I created a List box (list42) based on the
TNAMES table. Now when I open the form I select the name from the list box
then I can select records and add them to the play list.
Here is my question: When the record is written to the table TPlaylistSect
how can I also grab the valuse from List42 that is present on the form and
write it also to personsname field. I hope someone may have an answer. Keep
in mind it doesnt have to be a listbox I could always create a combo box to
do the same thing.
Thanks.
Option Compare Database
Option Explicit
Dim xlstAvailable As Access.ListBox
Dim xlstSelected As Access.ListBox
Dim strItem As String
Dim strSQL As String
Dim dbs As DAO.Database
Dim rstAvailable As DAO.Recordset
Dim rstSelected As DAO.Recordset
Dim rstPersonAvailable As DAO.Recordset
Dim strSearch As String
Dim varItem As Variant
Private Sub cmdAdd_Click()
'Written by Helen Feddema 11-2-2000
'Last modified 11-14-2000
On Error GoTo ErrorHandler
Set xlstSelected = Me![ResultMP3]
Set xlstAvailable = Me![List50]
'Check that at least one item has been selected
If xlstAvailable.ItemsSelected.Count = 0 Then
MsgBox "Please select at least one item"
xlstAvailable.SetFocus
Exit Sub
End If
Set dbs = CurrentDb
Set rstSelected = dbs.OpenRecordset("TPlaylistSelect", dbOpenDynaset)
Set rstAvailable = dbs.OpenRecordset("TMP3", dbOpenDynaset)
For Each varItem In xlstAvailable.ItemsSelected
strItem = Nz(xlstAvailable.Column(0, varItem))
Debug.Print "Selected item: " & strItem
'Append selected item to Selected Items list
With rstSelected
strSearch = "[MP3] = " & Chr$(39) & strItem & Chr$(39)
.FindFirst strSearch
If .NoMatch = True Then
.AddNew
![MP3] = strItem
.Update
End If
End With
'Delete selected item from Available Items list
'With rstAvailable
'strSearch = "[MP3] = " & Chr$(39) & strItem & Chr$(39)
'.FindFirst strSearch
'If .NoMatch = False Then
' .Delete
'End If
'End With
Next varItem
rstSelected.Close
rstAvailable.Close
xlstAvailable.Requery
xlstSelected.Requery
playlist to play MP3's and the below code works.
However, I wanted to store the records under someones name. So what I did
was added a field to the TPlaylistSelect table called personsname. I also
made another table called TNAMES to store the persons name who wants to make
the playlist. So on my form I created a List box (list42) based on the
TNAMES table. Now when I open the form I select the name from the list box
then I can select records and add them to the play list.
Here is my question: When the record is written to the table TPlaylistSect
how can I also grab the valuse from List42 that is present on the form and
write it also to personsname field. I hope someone may have an answer. Keep
in mind it doesnt have to be a listbox I could always create a combo box to
do the same thing.
Thanks.
Option Compare Database
Option Explicit
Dim xlstAvailable As Access.ListBox
Dim xlstSelected As Access.ListBox
Dim strItem As String
Dim strSQL As String
Dim dbs As DAO.Database
Dim rstAvailable As DAO.Recordset
Dim rstSelected As DAO.Recordset
Dim rstPersonAvailable As DAO.Recordset
Dim strSearch As String
Dim varItem As Variant
Private Sub cmdAdd_Click()
'Written by Helen Feddema 11-2-2000
'Last modified 11-14-2000
On Error GoTo ErrorHandler
Set xlstSelected = Me![ResultMP3]
Set xlstAvailable = Me![List50]
'Check that at least one item has been selected
If xlstAvailable.ItemsSelected.Count = 0 Then
MsgBox "Please select at least one item"
xlstAvailable.SetFocus
Exit Sub
End If
Set dbs = CurrentDb
Set rstSelected = dbs.OpenRecordset("TPlaylistSelect", dbOpenDynaset)
Set rstAvailable = dbs.OpenRecordset("TMP3", dbOpenDynaset)
For Each varItem In xlstAvailable.ItemsSelected
strItem = Nz(xlstAvailable.Column(0, varItem))
Debug.Print "Selected item: " & strItem
'Append selected item to Selected Items list
With rstSelected
strSearch = "[MP3] = " & Chr$(39) & strItem & Chr$(39)
.FindFirst strSearch
If .NoMatch = True Then
.AddNew
![MP3] = strItem
.Update
End If
End With
'Delete selected item from Available Items list
'With rstAvailable
'strSearch = "[MP3] = " & Chr$(39) & strItem & Chr$(39)
'.FindFirst strSearch
'If .NoMatch = False Then
' .Delete
'End If
'End With
Next varItem
rstSelected.Close
rstAvailable.Close
xlstAvailable.Requery
xlstSelected.Requery