Results 1 to 4 of 4

Thread: DoCmd.OpenQuery

  1. #1
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I can do this for a form:

    DoCmd.OpenForm FormName:="frm_Show Master", WhereCondition:="[ShowNo]=1", Windowmode:=acWindowNormal

    I can do this for a report:

    DoCmd.OpenReport ReportName:="rpt Show Master", WhereCondition:="[ShowNo]=1", View:=acPreview


    I can do this for a query:

    DoCmd.OpenQuery "qry Show Master - 1", acNormal, acEdit

    where [ShowNo] =1


    Is there a way of doing:

    DoCmd.OpenQuery "qry Show Master" and set the WhereCondition


    Thanks in advance for any help with this
    Cheers,
    Andy

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='AGMCon' post='763705' date='05-Mar-2009 20:29'][/quote]

    You can't add a where condition for the instruction DoCmd.OpenQuery.

    The only way to do this is write code to modify the SQL of the query .
    Francois

  3. #3
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Francois,

    Some day in my spare time, I'll learn how to code SQL
    Cheers,
    Andy

  4. #4
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts
    Many of us learn by using the Query Builder and then looking at the SQL it creates. The next step is to create a SQL string in VBA, and concatenate and Where conditions at the appropriate points. Then you check it by stepping to the point where the SQL string has been built and do a debug print. Then copy that and paste it into a new query in SQL view and see if it behaves. Or you can sit and read a book....
    Wendell

Posting Permissions

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