Results 1 to 7 of 7
  1. #1
    Lounger
    Join Date
    Jul 2005
    Location
    Lancaster, Delaware, USA
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    List Boxes (Access 2000)

    Hello,
    I would like to know if there is a way (I know there is) for a user to click on an item in a list box and once this record/item is selected that the list box then acts upon the selection. I have a list box that passes the selected information to a pre-defined query as a parameter and instead of having a command button I would like it if once the user selects a record that this record is passed as a parameter to the query. The user will never select more than one record. Any help will be very much appreciated.

  2. #2
    5 Star Lounger
    Join Date
    Nov 2004
    Location
    Wilmington, North Carolina, USA
    Posts
    1,196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List Boxes (Access 2000)

    Mickey,
    Do you want the query to automatically run after an item is selected? Or do you want it to run after a command button is clicked? Could you paste your query SQL here? (To view your query's SQL, right click on the query's title bar while in design vew, and select SQL View). Also - please identify which field you wish to filter by.
    ____________________________
    Jeremy
    "If you spend more on coffee than on IT security, then you will be hacked. What's more, you deserve to be hacked." -Richard Clarke

  3. #3
    Lounger
    Join Date
    Jul 2005
    Location
    Lancaster, Delaware, USA
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List Boxes (Access 2000)

    Actually the command button I am looking to replace runs a macro which in turn runs a query. The query is looking for a parameter in the combo box on the form and when the command button is clicked it runs the query passing the item selected in the combo box as a parameter to the query. All I am really looking to do is replace the combo box and the command button with a list box or something similar. Now If it is possible I would like it to once the user selects the record in the list box that that record be passed as a parameter and the query to run. Right now I reference the combobox in the query as follows."Like [Forms]![frmAssemblyPCBSearch]![cboPCBSearch]". I guess what i'm trying to do is replace the macro with a list box that once selected passes the record selected to the query and then runs it. Thanks for the reply and any additional information you supply will also be very much appreciated.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: List Boxes (Access 2000)

    Welcome to Woody's Lounge!

    You can use code in the On Click event of the list box. Personally, I'd rather use a command button, or the On Dbl Click event of the list box, for using the On Click event means that the user isn't allowed any mistakes - each time the user clicks or selects an item in the list box, the query is run, even if the user accidentally clicks the same item twice, or clicks the wrong item.

    To create code for the On Click event of a list box named lstSelect on a form frmMyForm:

    - Set the parameter in the query to [Forms]![frmMyForm]![lstSelect]
    - Open the form in design view.
    - Select the list box.
    - Activate the Event tab of the Properties window.
    - Click in the On Click box, and select [Event Procedure] from the dropdown list.
    - Click the ... button to the right of the dropdown arrow.
    - Make the code look like this:

    Private Sub lstSelect_Click()
    If lstSelect.ListIndex = -1 Then Exit Sub
    DoCmd.OpenQuery "MyQuery"
    End Sub

    - Switch back to Access and save the form.

  5. #5
    Lounger
    Join Date
    Jul 2005
    Location
    Lancaster, Delaware, USA
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List Boxes (Access 2000)

    Hans,
    You are always a great help. I knew it would be something simple like what you posted does exactly what I want it to. Thank you very much.

  6. #6
    4 Star Lounger SteveH's Avatar
    Join Date
    Jan 2001
    Location
    Chelsea, Gtr London, United Kingdom
    Posts
    587
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List Boxes (Access 2000)

    Just a consideration from an interface design perspective.
    The Windows paradigm usually distinguishes between a single click and a double-click.
    If your query is to perform an action or a drill-down or something like that you might want to use the Dbl_Click event. A single click implies the user is making a selection prior to doing something else.
    Steve H
    IT Lecturer/Access Developer
    O2K SR3/O2010; Win7Pro

  7. #7
    Lounger
    Join Date
    Jul 2005
    Location
    Lancaster, Delaware, USA
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List Boxes (Access 2000)

    Thanks Steve that makes alot of sense.

Posting Permissions

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