Available Selected Fields
LstQue LstStaff
____________ _____________
| | | |
| | -> | |
| | ->> | |
| | | |
| | <- | |
| | <<- | |
|__________| |___________|
Available has a hidden key of StaffID and diplays Staff Name.
Selected needs to have the StaffID transfered(hidden) and have the Staff Name displayed.
I want to store the StaffID in the Selected Listbox to the database. Right now, I can only get EITHER the StaffID transfered or the Staff Name not both.
Here's the code:
Private Sub MoveToLstStaff()
Dim AvailCounter As Integer, SelectedCounter As Integer
Dim AvailList As Integer, SelectedList As Integer
Dim Liststr As String, FoundInList As Integer
Dim X As Variant
AvailList = lstQue.ListCount - 1
SelectedList = lstStaff.ListCount - 1
For AvailCounter = 0 To AvailList
If lstQue.Selected(AvailCounter) = True Then
If IsNull(lstStaff.RowSource) Then
Liststr = lstQue.Column(0, AvailCounter) & ";"
lstStaff.RowSource = Liststr
Else
FoundInList = False
For SelectedCounter = 0 To SelectedList
If lstStaff.Column(0, SelectedCounter) = _
lstQue.Column(0, AvailCounter) Then
FoundInList = True
End If
Next SelectedCounter
If Not FoundInList Then
Liststr = lstStaff.RowSource & _
lstQue.Column(0, AvailCounter) & ";"
lstStaff.RowSource = ""
lstStaff.RowSource = Liststr
End If
End If
End If
Next AvailCounter
For X = 0 To lstStaff.ListCount - 1
lstStaff.Selected(X) = True
Next X
'lstStaff.Selected(0) = True
End Sub
Private Sub SaveToDB_Click()
Dim rstUpdate As DAO.Recordset
Dim dbsUpdate As DAO.Database
'Dim lstQue As ListBox
Dim varSelected As Variant
'Dim strSql As String
Set dbsUpdate = CurrentDb
Set rstUpdate = dbsUpdate.OpenRecordset("TestListBoxAdd"
With rstUpdate
For Each varSelected In Me.lstStaff.ItemsSelected
.AddNew
!StaffID = lstStaff.Column(0, varSelected)
!DateOfSAL = ActDateOfSAL.Value
!DateRec = actDateRec.Value
.Update
Next varSelected
End With
End Sub
Thanks,
Brad Boydston
boydston@bertnash.org