Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    opoen report with where condition (Access 2000)

    I have a report based on the following sql:
    SELECT products.grade, products.code, products.size, products.Productid
    FROM products
    ORDER BY products.grade, products.size;


    I want to open a report from a form with the Where Condition :
    WHERE ((([products].[size])=205))
    Also i want to open the report with the following where condition:

    WHERE ((([products].[size])=6))

    I am afraid the way i have built the code is not right. It is the following:


    Dim stDocName As String
    stDocName = "rptLists"
    DoCmd.OpenReport stDocName, acPreview WHERE ((([products].[size])=205))

    Can somebody help me?

  2. #2
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Nevada, USA
    Posts
    207
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: opoen report with where condition (Access 2000)

    Instead of hard coding the where into the open report, try setting up a string variable (call it strwhere) as follows:
    strwhere = "[products].[size]) = " & sizevar

    where sizevar is a variable that you set to either 205 or 6 or whatever else is required.

    Then the open statement would look like:

    DoCmd.OpenReport stDocName, acViewPreview, , strwhere

    HTH.
    Carol W.

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: opoen report with where condition (Access 2000)

    As WSC pointed out, the wherecondition argument has to be a string that includes the field name and the condition. It never includes the word "where", only the rest of the statement. If you want more than one condition, you simply join them with AND or OR. For example:

    strWhere = "[size]=205 OR [size]=6"
    Charlotte

Posting Permissions

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