View Full Version : Count(*) variable ?


supmktg
08-08-2005, 08:03 PM
I'm having a problem with the rowsource of a listbox. The rowsource query has a Group by clause, and if the recordcount is 0, it shows one fictitious row with an ID of 0 and a date of 11/30/1899 ( the rowsource query uses a linked table that I have no control over). If I remove the Group by clause, the fictitious record goes away.

I'm trying to add :

SELECT Count(*) AS TotalRecords
FROM qryConsTransCount;

to my vba code to determine if the rowsource should include the group by or not. How can I assign the above sql to a variable so I can do this:

If variable >1 then
'use rowsource that includes Group by
else
'use rowsource without Group by
end if

Thanks,

Sup

WayneRyan
08-08-2005, 09:11 PM
Sup,

You can use a DCount function to count the number of rows returned
by the query.

lngTotalRows = DCount("[SomeField]", "qryConsTransCount")

Wayne

Pat Hartman
08-08-2005, 09:29 PM
Sounds like a design issue to me. Every combo should have a table with a unique set of values. You shouldn't have to do a group by to get rid of duplicates.

supmktg
08-09-2005, 04:35 AM
Wayne,

Thank you very much, DCount does the trick!

Sup

P.S. Pat, I know it's a design issue. As I stated, there's a poorly designed linked (ODBC) table involved over which I have no control. I needed a way around it and this seemed like a good alternative.