Results 1 to 6 of 6
  1. #1
    Join Date
    May 2022
    Posts
    4

    DSUM with dual criteria

    I am writing a short procedure to query DSUM subtotals of a table TaRegister_New and then write the answer in a text box. I am having trouble with the dual criteria. Putting the criteria into a sting made checking easier. I have been trying for a couple of days.



    strSQL = "([IDOwner] = " & intOwner & " ) AND ([ID_Company] = " & intCompany & ")"
    strSQL2 = "([IDOwner] = " & intOwner & " )"
    strSQL3 = "([ID_Company] = " & intCompany & ")"

    dblCumulativeShares = DSum("nz(ShNumBuy) * Nz(Split)", "TaRegister_New", strSQL)

    I want the answer from strSQL, the dual criteria. There is no error message, but the result is 0, the criteria is wrong.
    Using strSQL2 or strSQL3, i get a correct answer for that query, but without the dual criteria, the answer is meaningless.
    Using Deebug.Print, strSQL prints out as
    ([IDOwner] = 2 ) AND ([ID_Company] = 166)
    , with the code correctly picking up values for IDOwner and ID_Company. They are integers.

    I have tried different formatting for the Criteria, but I'm getting nowhere. I am doing something wrong with the format of AND.
    Any help appreciated.

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Please try this:

    Code:
    DSum("nz(ShNumBuy) * Nz(Split)", "TaRegister_New", "[IDOwner] = " & intOwner & " AND [ID_Company] = " & intCompany)
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    Join Date
    May 2022
    Posts
    4
    Thanks. No it still doesn't work. No error code, just gives an answer of zero.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    So paste that into a sql window.
    What do you get?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Join Date
    May 2022
    Posts
    4
    Yes I tried.
    I generated the SQL in a query, then substituted hard values (2 and 166) for variables.
    Now it doesn't work

  6. #6
    Join Date
    May 2022
    Posts
    4

    Solved

    Went back and reviewed. The code is correct. The CALL procedure entered the wrong data. Thank you for the prompt.

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

Similar Threads

  1. dsum two criteria in vba
    By diegomarino in forum Access
    Replies: 1
    Last Post: 05-18-2022, 07:06 AM
  2. Help me ! using Dsum with criteria day
    By dahota in forum Forms
    Replies: 4
    Last Post: 06-25-2015, 11:05 AM
  3. Dsum criteria
    By Manuel Ferreira in forum Access
    Replies: 4
    Last Post: 09-12-2014, 09:54 AM
  4. dsum with criteria Not like 38,39,40,41
    By sdel_nevo in forum Programming
    Replies: 3
    Last Post: 06-13-2013, 03:23 PM
  5. Dsum criteria
    By bdaniel in forum Queries
    Replies: 4
    Last Post: 11-27-2011, 03:41 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