boblarson
Smeghead
- Local time
- Today, 09:36
- Joined
- Jan 12, 2001
- Messages
- 32,040
I'm trying to assign a pre-built query (which is built from other queries) to a DAO recordsource, but I keep getting the "too few parameters, expected 2" error.
I suspect it has to do with the fact that in one of the preceding queries I am narrowing down data via Max on date and also the value between two dates (from text boxes). But, I can't figure out how to assign the parameters to the recordset so it will open.
my code to open the recordsource is:
Set rstDemo = db1.OpenRecordset("04 qryAsthma_Ethnicity_Totals")
The SQL behind that query is:
SELECT tlkpEthnicity.EthRollup, Count([04 qryAsthma_Ethnicity].CountOfEthnicity) AS TotalEthnic
FROM [04 qryAsthma_Ethnicity] INNER JOIN tlkpEthnicity ON [04 qryAsthma_Ethnicity].Ethnic = tlkpEthnicity.Ethnicity
GROUP BY tlkpEthnicity.EthRollup;
and that query is built upon:
PARAMETERS Forms!frmReportsMain!txtBegDate DateTime, Forms!frmReportsMain!txtEndDate DateTime;
SELECT [00 qry_Asthma_At_Last_Visit].clinic_code, [00 qry_Asthma_At_Last_Visit].ethnicity AS Ethnic, 1 AS CountOfEthnicity, [00 qry_Asthma_At_Last_Visit].MaxOfvisit_date AS VDate
FROM [00 qry_Asthma_At_Last_Visit]
WHERE ((([00 qry_Asthma_At_Last_Visit].MaxOfvisit_date) Between [Forms]![frmReportsMain]![txtBegDate] And [Forms]![frmReportsMain]![txtEndDate]));
and finally, that one is built on:
SELECT tblVisits.clinic_code, tblVisits.chart_number, Max(tblVisits.visit_date) AS MaxOfvisit_date, tblVisits.hlth_asthma, tblDemo.ethnicity
FROM tblVisits LEFT JOIN tblDemo ON (tblVisits.chart_number = tblDemo.chart_number) AND (tblVisits.clinic_code = tblDemo.clinic_code)
GROUP BY tblVisits.clinic_code, tblVisits.chart_number, tblVisits.hlth_asthma, tblDemo.ethnicity
HAVING (((tblVisits.hlth_asthma)=True));
Any assistance with how to run parameterized queries from VBA would be great.
Thanks,
Bob Larson
I suspect it has to do with the fact that in one of the preceding queries I am narrowing down data via Max on date and also the value between two dates (from text boxes). But, I can't figure out how to assign the parameters to the recordset so it will open.
my code to open the recordsource is:
Set rstDemo = db1.OpenRecordset("04 qryAsthma_Ethnicity_Totals")
The SQL behind that query is:
SELECT tlkpEthnicity.EthRollup, Count([04 qryAsthma_Ethnicity].CountOfEthnicity) AS TotalEthnic
FROM [04 qryAsthma_Ethnicity] INNER JOIN tlkpEthnicity ON [04 qryAsthma_Ethnicity].Ethnic = tlkpEthnicity.Ethnicity
GROUP BY tlkpEthnicity.EthRollup;
and that query is built upon:
PARAMETERS Forms!frmReportsMain!txtBegDate DateTime, Forms!frmReportsMain!txtEndDate DateTime;
SELECT [00 qry_Asthma_At_Last_Visit].clinic_code, [00 qry_Asthma_At_Last_Visit].ethnicity AS Ethnic, 1 AS CountOfEthnicity, [00 qry_Asthma_At_Last_Visit].MaxOfvisit_date AS VDate
FROM [00 qry_Asthma_At_Last_Visit]
WHERE ((([00 qry_Asthma_At_Last_Visit].MaxOfvisit_date) Between [Forms]![frmReportsMain]![txtBegDate] And [Forms]![frmReportsMain]![txtEndDate]));
and finally, that one is built on:
SELECT tblVisits.clinic_code, tblVisits.chart_number, Max(tblVisits.visit_date) AS MaxOfvisit_date, tblVisits.hlth_asthma, tblDemo.ethnicity
FROM tblVisits LEFT JOIN tblDemo ON (tblVisits.chart_number = tblDemo.chart_number) AND (tblVisits.clinic_code = tblDemo.clinic_code)
GROUP BY tblVisits.clinic_code, tblVisits.chart_number, tblVisits.hlth_asthma, tblDemo.ethnicity
HAVING (((tblVisits.hlth_asthma)=True));
Any assistance with how to run parameterized queries from VBA would be great.
Thanks,
Bob Larson