Avatar of thandel
thandel
 asked on

Help with DCount Syntax

I am using Dcount to look if a field (CL - String) in a table has a particular date of another field (DiscoDiag - Date) in MS Access 2003.

I'm testing with the following VBA line but getting an error.  I believe its just my syntax or placement of quotes.  I want to put up a message when the date of DiscoDiag is after todays date.  Any help is appreciated.

If DCount("*", "tCl", "CL = """ & sFindODBrand & """ And DiscoDiag < Now()""") > 0 Then MsgBox "BAM!"
Microsoft AccessVBA

Avatar of undefined
Last Comment
thandel

8/22/2022 - Mon
Anders Ebro (Microsoft MVP)

Try this:
If DCount("*", "tCl", "CL = """ & sFindODBrand & """ And DiscoDiag < Now()") > 0 Then MsgBox "BAM!"

Open in new window

ASKER CERTIFIED SOLUTION
Bill Prew

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
PatHartman

You didn't tell us what the error message was.   The best technique for  creating strings like this Where clause is to build it into a variable so that you can view the completed string when you get an error.

Dim strWHERE as string
strWHERE = "CL = """ & sFindODBrand & """ And DiscoDiag < Now()"""

If DCount("*", "tCl", strWHERE) > 0 Then MsgBox "BAM!"
thandel

ASKER
Thanks!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy