Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2004
    Posts
    364

    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.

    How should I go about it?

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    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.
    Code:
    Private Sub MyListBox_AfterUpdate()
     
        Me.MyTextBox.Value = DCount("LibraryName", "Visits", "LibraryName = '" & Me.MyListBox.Value & "'")
    
    Ens Sub
    Have a nice day!

  3. #3
    Join Date
    Aug 2004
    Posts
    364
    that works a treat! Thank you

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •