Originally Posted by
Gicu
Yes, of course, the code that I gave you to do the updates would not change much - you would simply need to reference the new listbox holding the selected items and changing from looping through the ItemsSelected to looping through all items (
https://stackoverflow.com/questions/...ugh-a-list-box) because do not reselect them in the listbox once you move them there from "available". Here is a link you might want to have a look at:
https://office-watch.com/2010/adding...-items-part-2/ (the topic came up yesterday in this forum:
https://www.accessforums.net/showthr...826#post417826).
You may also want to consider the way you do the update itself; right now you are overwriting the entire content of the comments field for the selected records with the "new" comment. As I do not know the specifics of your db that might be OK. I usually design dbs to have the "comments" (or "notes") in another table in which I store the main record ID as a foreign key, the comment, timestamp (using Now()) and the user that added the comments. In this way I have a nice historical "comments" table.
Cheers,
Vlad
I tried following the tutorial from the office-watch link you provided but am unsuccessful. I copied some of the code from the link and made a few minor adjustments but it's not working.
Any more help would be greatly appreciated.
Code:
Private Sub cmdAdd_Click()
Dim strSQL As String
strSQL = "SELECT [qryCreateHold].[WorkOrderID_FK], [qryCreateHold].[WorkOrder] FROM qryCreateHold ORDER BY [WorkOrder]; "
On Error GoTo ErrorHandler
Set lstSelected = Me![lstSelectWorkOrders]
Set lstAvailable = Me![lstAvailableWorkOrders]
'Check that at least one item has been selected
If lstAvailable.ItemsSelected.Count = 0 Then
MsgBox "Please selecet at least one Work Order.", vbOK
lstAvailable.SetFocus
GoTo ErrorHandlerExit
End If
'Add selected items to an array, since removing an item
'from the list with RemoveItem clears the selections
intItem = 0
lngCount = lstAvailable.ItemsSelected.Count
ReDim Listitems("lngCount – 1")
For Each varItem In lstAvailable.ItemsSelected
Listitems(intItem) = Nz(lstAvailable.Column(0, varItem))
intItem = intItem + 1
Next varItem
For i = 0 To lngCount - 1
strItem = Listitems(i)
'Append selected item to Selected Items value list
lstSelected.AddItem strItem
'Delete selected item from Available Items value list
lstAvailable.RemoveItem strItem
Next i
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox "Error " & Err.Number & " in YourProcName procedure: " & Err.Description, vbCritical, "Application error"
Resume ErrorHandlerExit
End Sub
Private Sub cmdRemove_Click()
On Error GoTo ErrorHandler
Set lstSelected = Me![lstSelectedItems]
Set lstAvailable = Me![lstAvailableItems]
'Check that at least one item has been selected
If lstSelected.ItemsSelected.Count = 0 Then
MsgBox "Please selecet at least one Work Order.", vbOK
lstSelected.SetFocus
GoTo ErrorHandlerExit
End If
'Add selected items to an array, since removing an item
'from the list with RemoveItem clears the selections
intItem = 0
lngCount = lstSelected.ItemsSelected.Count
ReDim Listitems("lngCount – 1")
For Each varItem In lstSelected.ItemsSelected
Listitems(intItem) = Nz(lstSelected.Column(0, varItem))
intItem = intItem + 1
Next varItem
For i = 0 To lngCount - 1
strItem = Listitems(i)
'Append selected item to Selected Items value list
lstAvailable.AddItem strItem
'Delete selected item from Available Items value list
lstSelected.RemoveItem strItem
Next i
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox "Error " & Err.Number & " in YourProcName procedure: " & Err.Description, vbCritical, "Application "
Resume ErrorHandlerExit
End Sub
Private Sub Form_Load()
On Error GoTo ErrorHandler
DoCmd.RunCommand acCmdSizeToFitForm
Me![lstAvailableItems].RowSource = strSQL
Me![lstSelectedItems].RowSource = “”
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox "Error " & Err.Number & " in YourProcName procedure: " & Err.Description, vbCritical, "Application "
Resume ErrorHandlerExit