Vba sql + dcount (1 Viewer)

habiler

Registered User.
Local time
Today, 01:11
Joined
Aug 10, 2014
Messages
70
Hi Everybody,

Whats wrong with my code ??
newSQL1 = "SELECT CODE, DCOUNT(PERIODE,Maladies,"PERIODE = '01/01/2017'")AS Teller FROM Maladies "
Habiler
 

Minty

AWF VIP
Local time
Today, 00:11
Joined
Jul 26, 2013
Messages
10,379
Dates in access must be surrounded by # # in access. Also your query isn't efficient, you shouldn't use domain functions (DCount, Dlookup etc ) in a query.

You can rewrite it as
Code:
"SELECT Code , Count(Periode) as Teller FROM Maladies WHERE Periode = #01/01/2017# Group By Code"
 

plog

Banishment Pending
Local time
Yesterday, 18:11
Joined
May 11, 2011
Messages
11,674
I vote that the thing wrong with your code is the DCount appearing at all. There's no reason for Domain functions (DCount, DMax, etc.) in SQL. Instead you build an aggregate query to get that information:

SELECT COUNT(PERIODE) AS Teller FROM Maladies WHERE PERIODE=#1/1/2017;
 

Users who are viewing this thread

Top Bottom