Results 1 to 9 of 9
  1. #1
    UnrealEnvy is offline Novice
    Windows 7 Access 2007
    Join Date
    Aug 2009
    Posts
    5

    How to make A combobox run a query?

    Hello everyone!
    I'm farily new to access, and would like assistance, in this (I guess) easy question.

    I would like to have a combo box, on a form, with values in it.
    When I choose value 1 I would like to run Query 1
    When I choose value 2 I would like to run Query 2
    and so on.



    Please explain how to do this, considering I'm new to this.
    Thank you a lot!

  2. #2
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    Ok

    Lets say you combo box contains 2 columns 1 hidden and 1 not the one that is not hidden is a user friendly description of the query you want to run. The hidden on is the actual name of the query in Access.

    On the after update event of the Combo box enter

    DoCmd.OpenQuery Me.Combo

    Bear in mind that this only works for action queries. You have not said what type of query you want to run.

    David

  3. #3
    UnrealEnvy is offline Novice
    Windows 7 Access 2007
    Join Date
    Aug 2009
    Posts
    5
    Hey David, thank you for the reply.
    The query is one that lets the user search for a word in a field.

    I didn't quite succeed in what you told me to do. Sorry, I'm fairly new, and might need a little more detailed explanation on how to perform this. Please be patient, I appreciate the help a lot.

    BTW, I don't know any VB, so please tell me how to do this in Access only.
    Thank you.

  4. #4
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    Ok that makes things a little more clearer. It appears to me that you want to display the contents of a query in a subform, or thats what it should be doing. Your query has parameters set on a text field that prompts the user to enter a word upon which the query runs and returns all records that match whatever has been typed in. Correct so far?

    The problem you have is that your subform will not know its recrodsource until you have selected the item from the combo box.

    In your combo box go to propertoes and change the row source type to value list.

    Then in your rowsource enter

    "Qry1","Description","Qry2","Description","etc","e tc"

    Make the column widths 0cm,3,cm

    Make the bound column column 1

    On the afterupdate of the combobox enter

    Me.MainForm!Subform.Recordsource = Me.Combo

    This should then change the recordsource to match what you have selected in the combo.

    Remember I have used psuedonames for brevity you need to use actual names in your mdb.

    David

  5. #5
    UnrealEnvy is offline Novice
    Windows 7 Access 2007
    Join Date
    Aug 2009
    Posts
    5
    I got everything except the After Update part.
    I don't understand how to match that line to my own needs... =/
    Sorry I'm putting you through my own troubles, it's just I know no one that can help me out.

  6. #6
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    Am I right with the fact that you are using a mainform / subform setup?

  7. #7
    UnrealEnvy is offline Novice
    Windows 7 Access 2007
    Join Date
    Aug 2009
    Posts
    5
    Not exactly.
    I got the form, on which I'd like the combobox to be.
    Then, the actual query will be opened, in a regular table view.

  8. #8
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    You shold not be using native queries to view results. The query should be the recordsource of a subfrom. This is more professional and prevents the user from being able to design the query once loaded. If you were to simply open a query as a datasheet then the menu would provide design caperbilities which is not what you want.

    David

  9. #9
    UnrealEnvy is offline Novice
    Windows 7 Access 2007
    Join Date
    Aug 2009
    Posts
    5
    Thank you, but is there anyone who can show me how to pull this off?
    I mean, you guys ought to know how to make a combobox that when I choose a value will run a query, or better - a form.
    I'm just asking for you to show me.

    Can someone please help?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Make Table Query Issue
    By tmcrouse in forum Access
    Replies: 0
    Last Post: 07-23-2009, 03:20 PM
  2. Make a table query
    By Fiona in forum Access
    Replies: 4
    Last Post: 06-25-2009, 11:24 AM
  3. Query based on Value in a Combobox
    By martinwd in forum Queries
    Replies: 3
    Last Post: 06-02-2009, 02:21 PM
  4. Replies: 0
    Last Post: 04-17-2008, 09:24 AM
  5. query based on two combobox
    By datto in forum Queries
    Replies: 0
    Last Post: 04-18-2007, 11:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums - Senior Forums