Counting Records in SQL (1 Viewer)

exaccess

Registered User.
Local time
Today, 21:17
Joined
Apr 21, 2013
Messages
287
What is the best way to attack the problem. Here is sample code, which was working yesterday and after the addition of a column to the underlying table to day does not work.
Code:
I = DCount("Language", "[" & Orig & "]", "[Language] <> 'X'")
Here I is integer counter, Language is the name of field . Orig is the underlying table name. Help please
 

Minty

AWF VIP
Local time
Today, 20:17
Joined
Jul 26, 2013
Messages
10,371
You are making that more complicated than it needs to be. Try

Code:
I = DCount("Language", "Orig", "[Language] <> 'X'")
 

exaccess

Registered User.
Local time
Today, 21:17
Joined
Apr 21, 2013
Messages
287
You are making that more complicated than it needs to be. Try

Code:
I = DCount("Language", "Orig", "[Language] <> 'X'")

Sorry for coming back after days but I had to rush to another project. May be I mislead you Orig is a variable which can take the name of a table. This construction does not work.
 

Minty

AWF VIP
Local time
Today, 20:17
Joined
Jul 26, 2013
Messages
10,371
Okay Try this

Code:
Dim sTableName as String
sTableName = Orig

i = Dcount("language",sTableName,"[Language] <> 'X'")
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:17
Joined
Sep 21, 2011
Messages
14,295
Minty,

Wouldn't
Code:
i = Dcount("language",Orig,"[Language] <> 'X'")
work just as well?
 

Minty

AWF VIP
Local time
Today, 20:17
Joined
Jul 26, 2013
Messages
10,371
It might but I wanted to ensure it was a string value, I should have added a debug in there to make the point I guess...
 

exaccess

Registered User.
Local time
Today, 21:17
Joined
Apr 21, 2013
Messages
287
Thanks Gasman and Minty. I will try the second version soon and come back .
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:17
Joined
Sep 21, 2011
Messages
14,295
It might but I wanted to ensure it was a string value, I should have added a debug in there to make the point I guess...

Ah, I see.
Thanks for explaining. I would never have thought of that.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:17
Joined
Feb 19, 2002
Messages
43,274
Best practice is to use only the letters a-z and A-Z and numbers 0-9 and the underscore "_" in your table and column names. Then you don't need to ever worry about when you might need those pesky square brackets.
 

Users who are viewing this thread

Top Bottom