Results 1 to 6 of 6
  1. #1
    tailored is offline Novice
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    3

    DCount Combining Property Name & Wildcard

    Hi

    I'm building a report that uses a specific table [tblDataRecords] and I'm using textboxes to present specific results that have stripped out certain other results.
    In order to achieve the desired output, I've created the following DCount but need to combine a textbox property name and a wildcard.

    The textbox contains a formatted date in this format: yyyymmdd

    Here are my Control Source DCounts that do not work :

    Code:
    =DCount("[RCODE]","tblDataRecords","[RCODE] = '99' AND [NAME] ='George Lucas' AND [REFERENCE] LIKE [RefDate]'*'")
    Code:
    =DCount("[RCODE]","tblDataRecords","[RCODE] = '99' AND [NAME] ='George Lucas' AND [REFERENCE] LIKE [RefDate]&'*'")

    To elaborate, my [REFERENCE] column in my table is made up of mixed data and I want to find only the records that start with a date, as formatted above, while also filtering for the other criteria in the DCount.

    I have managed to get the following source to work :


    Code:
    =DCount("[RCODE]","tblDataRecords","[RCODE] = '99' AND [NAME] ='George Lucas' AND [REFERENCE] LIKE'202*'")

    ... where "202" represents the beginning of 2021... but I am using a referenced date in the textbox [RefDate] as this is dynamic and changes based on =Now()-x ...

    So, as the date will have changed each time the Access file is opened, the following is my query:


    • I need to combine the property name [RefDate] and a wildcard of '*' in order to search for fields in the [REFERENCE] that match yyyymmdd and the next 10 unknown numeric characters.
      • for example
        • 202103161234567890


    The finished control source calculation will be placed in another text box.

    Thanks in advance for any guidance.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    You do not use quotes for numerics if that RCODE is numeric?
    I do not think you can use Like with Dates?

    Use the Year(),Month(), Day() functions perhaps?
    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
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Give a try to this way:
    Code:
    "[RCODE] = '99' AND [NAME] ='George Lucas' AND [REFERENCE] LIKE '" & [refDate] & "*'"
    or
    Code:
    "[RCODE] = '99' AND [NAME] ='George Lucas' AND [REFERENCE] LIKE '" & Left(year([refDate]),3) & "*'"

  4. #4
    tailored is offline Novice
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    3
    Thanks accesstos

    The second version has worked... couldn't get the first one to play nicely.
    Thanks for your help... very much appreciated.

  5. #5
    tailored is offline Novice
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    3
    Thanks Welshgasman

    The RCODE is numeric however I don't need to use it in calculations, so interpreting it as text is fine in this instance.
    How would I format your suggestion into my existing DCount formula?

    Thanks again

  6. #6
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Quote Originally Posted by tailored View Post
    Thanks accesstos

    The second version has worked... couldn't get the first one to play nicely.
    Thanks for your help... very much appreciated.
    You are welcome!

    At first, I posted the first version assumed that the textbox contains text and then I realized that is about formatted date.

    You can also use the Format() function to specify the date range of desired records for the specific
    year: Format([RefDate],"yyyy")
    month: Format([RefDate],"yyyymm")
    or day: Format([RefDate],"yyyymmdd")


    For example, to get the count for the specific month, the criteria become:
    Code:
    "[RCODE] = '99' AND [NAME] ='George Lucas' AND [REFERENCE] LIKE '" & Format([RefDate],"yyyymm") & "*'"
    Cheers,
    John

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

Similar Threads

  1. Replies: 2
    Last Post: 03-09-2021, 05:52 PM
  2. Using a wildcard if an IIF statement.
    By atlee in forum Programming
    Replies: 6
    Last Post: 02-23-2014, 04:02 PM
  3. Replies: 9
    Last Post: 12-05-2013, 11:48 AM
  4. Replies: 14
    Last Post: 07-22-2013, 12:39 PM
  5. Combining Two DCount expressions in one
    By nmodhi in forum Forms
    Replies: 1
    Last Post: 02-26-2010, 10:49 AM

Tags for this Thread

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