- Local time
- Today, 22:50
- Joined
- Jul 9, 2003
- Messages
- 17,486
I need to count the number of groups in a table, in code, so that if there is more than one group I can run some different code.
Using the query builder I built this code, which returns a query with rows equal to the number of groups.
Following query named “qryTrackerNoOfGrps”
Then I use this query below built with the query builder to count the number of rows in the above query.
Following query named “qryTrackerNoOfGrpsCount”
And that works fine as well! But…….
When I try and execute the above query in code I get the following error message:
Error Number -2147217904 “No value given for one or more of the required parameters”
Obviously I can’t run a query from within the code like this. The essence of it is, all I need to do is count the number of groups in the table. There must be a way to do this! Any help or advice gratefully received.
Using the query builder I built this code, which returns a query with rows equal to the number of groups.
Following query named “qryTrackerNoOfGrps”
Code:
SELECT tblUnits.UnitRepairToDept, tblDept.DeptName
FROM tblDept INNER JOIN tblUnits ON tblDept.DeptID = tblUnits.UnitRepairToDept
GROUP BY tblUnits.UnitRepairToDept, tblDept.DeptName, tblUnits.UnitRepairBatchNo
HAVING (((tblUnits.UnitRepairBatchNo)=[Forms]![frmTrackUnits]![cboBatchID]));
Following query named “qryTrackerNoOfGrpsCount”
Code:
SELECT Count(qryTrackerNoOfGrps.UnitRepairToDept) AS CountOfUnitRepairToDept
FROM qryTrackerNoOfGrps;
And that works fine as well! But…….
When I try and execute the above query in code I get the following error message:
Error Number -2147217904 “No value given for one or more of the required parameters”
Code:
strSQL = "SELECT Count(qryTrackerNoOfGrps.UnitRepairToDept) _
AS CountOfUnitRepairToDept FROM qryTrackerNoOfGrps"
Set cn = CurrentProject.Connection
Set rs = cn.Execute(strSQL)
intCountStore = rs!CountOfUnitRepairToDept
'MsgBox intCountStore
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
fCountSplits = intCountStore