Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2008

    Question Unanswered: How to open query from code


    I have some fields on form , text box and combobox.

    On click of button, i want to open a query bases on selection on form..

    How do I do that?

    Please let me know,

  2. #2
    Join Date
    Feb 2004


    The query criteria will be [Forms]![Your Form Name]![Your Field Name]
    If you want to run and display the query results from a command button the code is, docmd.openquey "Your query name"

    Hope this was what you were looking for.
    You know, I'm sick of following my dreams, man. I'm just going to ask where they're going and hook up with 'em later

  3. #3
    Join Date
    Nov 2008

    Exclamation Re


    I want to check certain condition before I apply that filter to query.
    Like if fields if "ALL" or if it is "empty" based on this criteria queries parameter will change. SO I can not just put [forms]![form name]![fields name] .

    For that do I have to create multiple queries? based on each selection criteria?

    If not , is there another way?

  4. #4
    Join Date
    Nov 2007
    Adelaide, South Australia
    Use If statements and build your WHERE clause.

    If Me.Somefield <> "ALL" Then vSQL = vSQL & " SomeField = " & Somefield

    And such like.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!

    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

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