Results 1 to 3 of 3
  1. #1
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398

    Using DCount, how to use a variable as the criteria

    Is it possible to use a variable as the criteria within a dcount statement?

    I've established a variable named strTestSring.

    I can't get this statement to work, DCount("*", "Holiday_Matrix", strTestString = (-1))



    Thanks in advance!

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I am assuming that strTestString is a variable that holds a field name in your table (or else it doesn't really make sense).

    If that is the case, this should work:
    Code:
    DCount("*", "Holiday_Matrix", myTestString & "=(-1)")
    (remember, everything enclosed in quotes is interpreted as literal text, so your variables need to be outside of that)

  3. #3
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398
    Thank you.

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

Similar Threads

  1. Dcount for 2 criteria date fields
    By rmd62163 in forum Access
    Replies: 4
    Last Post: 04-22-2014, 09:51 AM
  2. DCount with Multiple Criteria
    By Newbie11 in forum Reports
    Replies: 4
    Last Post: 05-25-2012, 09:04 AM
  3. How do you use DCOUNT for multiple criteria?
    By wwhit in forum Programming
    Replies: 5
    Last Post: 05-15-2012, 11:14 AM
  4. Mask for dcount criteria
    By akbigcat86 in forum Programming
    Replies: 3
    Last Post: 08-09-2010, 11:00 AM
  5. VBA DCount() with variable field name
    By drh in forum Programming
    Replies: 2
    Last Post: 07-13-2010, 12:36 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