Results 1 to 8 of 8
  1. #1
    jlindquist23 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Jan 2019
    Posts
    47

    DLookup - Multiple Criteria

    I'd like to count the numbers in a subform based on set of criteria below AND the count of number of records in the subform. I need them both to display in the main form HTRecord.
    1. I only want the records that coincide with the main form "ID".
    2. I'd like to only count records that don't have anything in the "LastRackQty" field.
    3. I'd like the count to be in the main form and not the subform, shown as "CountOfZeroLastRackQty"

    If tried lots of variations of this formula:
    =DCount(“LastRackQty","LoadData","ID = forms![HTRecord.ID]" AND “NZ(LastRackQty,0)>0")

    LoadData is the name of the Table behind LoadData_Subform
    PartData is the name of the table behind the main HTRecord form.


    They are link by "ID".
    Click image for larger version. 

Name:	Capture.JPG 
Views:	28 
Size:	191.9 KB 
ID:	50147

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    Put all the criteria into astring variable. Then debug.print it, until you get it correct. Then use that variable in the function.
    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

  3. #3
    xps35's Avatar
    xps35 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jun 2022
    Location
    Schiedam, NL
    Posts
    300
    Maybe something like:
    Code:
    =DCount(“LastRackQty","LoadData","ID = " & forms![HTRecord.ID] & " AND “ & NZ(LastRackQty,0) *>0)")
    Groeten,

    Peter

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Those [ ] characteres are misplaced and not even needed. If ID and calculated textbox are on main form, don't need form reference.

    =DCount("LastRackQty", "LoadData", "ID = " & ID & " AND NZ(LastRackQty,0)>0")

    Assumes LastRackQty is field in table/query LoadData.

    The second criteria probably not need as Null records should not be counted.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    O/P is specifically looking for Null in lastrackqty though?, so I would expect =0 ?
    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

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Ooops, see that now. Yes =0

    or

    =DCount("*", "LoadData", "ID = " & ID & " AND LastRackQty IS NULL")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    jlindquist23 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Jan 2019
    Posts
    47
    This one worked!
    =DCount("LastRackQty", "LoadData", "ID = " & ID & " AND NZ(LastRackQty,0)>0")
    Thank you!

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    Quote Originally Posted by jlindquist23 View Post
    This one worked!
    =DCount("LastRackQty", "LoadData", "ID = " & ID & " AND NZ(LastRackQty,0)>0")
    Thank you!
    Not what you initially said?
    2. I'd like to only count records that don't have anything in the "LastRackQty" field.
    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

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

Similar Threads

  1. Dlookup with multiple criteria
    By jeffhanner10@gmail.com in forum Programming
    Replies: 2
    Last Post: 02-05-2020, 02:07 PM
  2. multiple criteria in a dlookup
    By xmattxman in forum Programming
    Replies: 1
    Last Post: 04-04-2019, 08:21 AM
  3. Help with multiple criteria DLookup
    By jtm013 in forum Programming
    Replies: 7
    Last Post: 04-23-2015, 03:16 PM
  4. DLookup with multiple criteria
    By RunTime91 in forum Access
    Replies: 4
    Last Post: 02-08-2015, 08:28 PM
  5. Multiple criteria in DLookup
    By crowegreg in forum Forms
    Replies: 7
    Last Post: 06-22-2011, 01:47 AM

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