none
DoCmd.OpenQuery in Design View opening it in SQL view. RRS feed

  • Question

  • I am trying to use the DoCmd.OpenQuery to open a query in design view, however it opens it in SQL view.

    Here is my syntax:

    DoCmd.OpenQuery "query_name", acViewDesign

    Is there a way to have the user click on a button and have the query open up in design view (the grid designer)

    Thanks

    Follow Up...

    After having the query open in design view and clicking the save button, now this code works.

    • Edited by James N San Thursday, March 22, 2018 6:00 PM
    Thursday, March 22, 2018 5:48 PM

Answers

  • Can you switch the query from SQL view to design view manually? If so, then try saving it in design view and see if it resolves the issue.

    Depending upon the query some may only be displayed in SQL view.


    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Marked as answer by James N San Thursday, March 22, 2018 6:08 PM
    Thursday, March 22, 2018 5:58 PM

All replies

  • Is your query a union query? Or does it contain non-standard joins between tables? Such queries cannot be displayed in design view.

    But why do you want to use VBA code to open a query in design view? You, as developer, can open the query from the navigation pane, and end users should never view queries directly.


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Thursday, March 22, 2018 5:58 PM
  • Can you switch the query from SQL view to design view manually? If so, then try saving it in design view and see if it resolves the issue.

    Depending upon the query some may only be displayed in SQL view.


    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Marked as answer by James N San Thursday, March 22, 2018 6:08 PM
    Thursday, March 22, 2018 5:58 PM
  • No it is a simple one table query.

    Anyway see my follow up above.

    When I had it open in design view and clicked save, then the code worked, and keeps opening it in design view.

    To answer your question, we are taking the navigation pane away from the users, and the user of the database will need to be able to view the query in design view, to enter parameter information.

    I agree the user should never be able to have direct access to the query, but this is the policy.

    I am not going to build out a user interface so user can edit query indirectly.

    Thanks

    Thursday, March 22, 2018 6:07 PM
  • Yes that's exactly what I tried and it worked, and continues to work.

    Thanks.

    • Marked as answer by James N San Thursday, March 22, 2018 6:08 PM
    • Unmarked as answer by James N San Thursday, March 22, 2018 6:08 PM
    Thursday, March 22, 2018 6:07 PM