G
Guest
Hello,
Lets say I have a Query already created & the Query Name is "qryCustomersInNJ"
where the SQL code is
SELECT COUNT(*) AS NumOfRecords FROM tblCustomers WHERE State = 'NJ'
Now in my VBA code I want to get what the Count is using a Recordset.
Note I dont want to use the DCOUNT function.
How can I do this ?
I know I can use:
strRecordSetSource = "SELECT COUNT(*) AS NumOfRecords FROM tblCustomers
WHERE State = 'NJ'"
Set rst = CurrentDb.OpenRecordset(strRecordSetSource, dbOpenForwardOnly)
dblNumOfRecords = rst!NumOfRecords
rst.Close
Where this uses the SQL assigned to a string variable.
What I am looking for help on is if the Query is already created & then I
want to get the count on it without having to put the SQL in my VBA Code.
I tried:
Set rst = CurrentDb.OpenRecordset("qryCustomersInNJ", dbOpenForwardOnly)
dblNumOfRecords = rst!NumOfRecords
rst.Close
But I get an err 3061 "Too few parameters. Expected 2"
Can someone help me again get # of Records for an already Created Query ?
Any help would be greatly appreciated.
Thank you,
Jeff
Lets say I have a Query already created & the Query Name is "qryCustomersInNJ"
where the SQL code is
SELECT COUNT(*) AS NumOfRecords FROM tblCustomers WHERE State = 'NJ'
Now in my VBA code I want to get what the Count is using a Recordset.
Note I dont want to use the DCOUNT function.
How can I do this ?
I know I can use:
strRecordSetSource = "SELECT COUNT(*) AS NumOfRecords FROM tblCustomers
WHERE State = 'NJ'"
Set rst = CurrentDb.OpenRecordset(strRecordSetSource, dbOpenForwardOnly)
dblNumOfRecords = rst!NumOfRecords
rst.Close
Where this uses the SQL assigned to a string variable.
What I am looking for help on is if the Query is already created & then I
want to get the count on it without having to put the SQL in my VBA Code.
I tried:
Set rst = CurrentDb.OpenRecordset("qryCustomersInNJ", dbOpenForwardOnly)
dblNumOfRecords = rst!NumOfRecords
rst.Close
But I get an err 3061 "Too few parameters. Expected 2"
Can someone help me again get # of Records for an already Created Query ?
Any help would be greatly appreciated.
Thank you,
Jeff