What I have is a situation where I would like to have a listbox that is populated by a query of a table. When an item is double clicked, I want an update query to be run on the record that contains that information and then have the listbox update itself as that item would now be removed from it's source.
For an actual example, the production facility where I am employed gets some raw materials on railcars. All the cars are to be tracked in a database. I have a form with a listbox on it that querys the table storing the info on railcars for ones that are onsite and full. What I want is when a record for a railcar in the listbox is double clicked, it's status to be changed to empty and the list should be updated to show that it is no longer full and on-site.
Is this possible or am I barking up the wrong tree?
When I double click on the item, it will perform the action on all items in the list, not just the one selected. Can the item selected be sent to an update query or does everything have to be done inside the event code?
you need to work out which record needs editing: the simplest way to see if you are headed in the right direction is to try to show the railcarID in a msgbox in the dblclick event.
best is for your listbox to have [railcarID] as the bound column, then in the dblclick event:
msgbox "I am working on record: " & listBoxName.value ' should work
once you can get the correct [railcarID] into the message box, you can also get it into an update query (or SQL statement etc etc).
the query criteria:
and now you can run the query from the dblclick event:
docmd.setwarnings false 'if you don't want to see warning messages
if this is an update query, only the matching record gets updated.
...substituting the real names for listBoxName, railcarID, theFormName, nameOfTheQuery of course!
and delete the msgbox line once it all works for you