Unanswered: How to show data in textbox from a query - based on listbox selection.
Hello, I need some help working out how to display a value from a query inside a textbox - based on clicking a row in a listbox.
My database shows visits to various libraries. I have a query which shows the number of visits for each library -
The query is created with the two tables (libraries) and (visits) which are one-to-many, 1 library can have many vistits. (The visits table counts the arrivals field, and the library table shows the library name).
A listbox on the main form shows info for each library e.g. address, name etc from the library table.
I want to be able to click on a row of the listbox to highlight a library and have the textbox on the form show how many visits that library has had - taken from the query.
Here is one possible solution. In this example, I suppose that the table "Visits" has a column "LibraryName" that contains the name of a library for each visit. I also suppose that the bound column of the listbox is the one containing the names of the libraries. Replace the object names (MyTextBox, MyListBox, etc.) by the names that are actually used on the form.
Private Sub MyListBox_AfterUpdate()
Me.MyTextBox.Value = DCount("LibraryName", "Visits", "LibraryName = '" & Me.MyListBox.Value & "'")