Results 1 to 12 of 12
  1. #1
    civl_eng is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    41

    DCOUNT Muliple criteria

    Hi all, i,m using Dcount for find duplicate value in table by tow criteria, in this table i want to find duplicate of Text480 in floor field by tow criteria, i write this code but it's not working :

    x = DCount("Floor", "tbl_Floor", "[fgk]= " & Me.Text60 & "And [Floor]= '" & Me.Text480 & "'")
    Attached Thumbnails Attached Thumbnails Dlookup.png  

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,445
    you are missing a space before And

  3. #3
    civl_eng is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    41
    thank you for reply, i correct this but its doesn't work again.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    Doesn't work means what - error message, wrong result, nothing happens?
    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
    civl_eng is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    41
    sorry wrong, with space before and it worked...now i have a question, can i do this with SQL in vba??? (Just for learning)

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    Not sure what you want. Yes, SQL statements can be constructed in VBA.
    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
    civl_eng is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    41
    i want to find Count of value in a Field by other field criteria, for example in above table i'm going to find Count of "Nine" when fgk is "5000" (Of course this values type in Text60 and Text480 ) , i wrote Below code in vba :

    DCount("Floor", "tbl_Floor", "[fgk]= " & Me.Text60 & " And [Floor]= '" & Me.Text480 & "'")

    i don't know
    whether I wrote it right or not, but its working for me, now my question is can i do this another way or with SQL code????


  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    Still not sure what you are asking for.

    Domain aggregate functions can be used in query, textbox, VBA.

    Also, an aggregate (GROUP BY) query can summarize data (count, sum, avg, etc).
    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.

  9. #9
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    You could open a recordset in VBA and then check the returned reordcount to see if there are existing records.
    In this case though , the DCount() will almost certainly be quicker and is simpler to write.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  10. #10
    Join Date
    Apr 2017
    Posts
    1,687
    In case you want to apply the formula to unbound tect box on form
    Code:
    =DCount("Floor","tbl_Floor","fgk = " & Nz([text60],9999999999) & " AND Floor = '" & [text480] & "'")

  11. #11
    civl_eng is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    41
    it's great, thanks you ArviLaanemets for guide, can you write this code In the form of SQL code in vba????

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    As Minty said, can construct an SQL SELECT statement to open recordset object.

    Do some research and learn about recordset objects. Start with http://allenbrowne.com/ser-29.html

    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("SELECT Count(*) AS CountRecs FROM tbl_Floor WHERE [fgk]= " & Me.Text60 & " And [Floor]= '" & Me.Text480 & "'", dbOpenDynaset)
    MsgBox rs!CountRecs


    Action SQL (DELETE, UPDATE, INSERT) can also be constructed and executed with VBA and do not involve recordset object. Research DoCmd.RunSQL and CurrentDb.Execute methods. DoCmd.OpenQuery can be used to run an Access action query object.
    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.

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

Similar Threads

  1. Criteria issue with DCount
    By JimO in forum Access
    Replies: 10
    Last Post: 08-29-2017, 11:56 AM
  2. DCount converse criteria
    By DubCap01 in forum Forms
    Replies: 5
    Last Post: 05-25-2015, 04:13 PM
  3. Using DCount, how to use a variable as the criteria
    By crowegreg in forum Programming
    Replies: 2
    Last Post: 02-17-2015, 05:18 PM
  4. DCount with Multiple Criteria
    By Newbie11 in forum Reports
    Replies: 4
    Last Post: 05-25-2012, 09:04 AM
  5. Mask for dcount criteria
    By akbigcat86 in forum Programming
    Replies: 3
    Last Post: 08-09-2010, 11:00 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