Hello,
I am working in Access 2003. I have a parameter query called
MonthlySalary_FinalQuery_TASK_TOTALS
I have set this query and its parameters in vba as follows:
Now, I need to query this query based on conditions in a loop, which loops throgh another recordset of subtasks and sets the name of the current subtask to variable currentsubtask. I am trying to accomplish this 're-querying' of the original query by setting up another recordset based on a sql string as follows:
When I try to compile, I get a 'Type mismatch' error. I realize that it is probably wrong to use the queryDef which defined the original query as a query in itself, but I am not sure how else to re-query the queryDef. Should I just put the original query in vba as a sql string and apply the currenttask condition right there? I was trying to avoid that since
MonthlySalary_FinalQuery_TASK_TOTALS is a really long sql statement and it would be a pain in the neck to format it with all the "" and &'s in the vba window.
Can anyone suggest an easy way to combine a querydef and sql string in vba? Any help would be greatly appreciated!
I am working in Access 2003. I have a parameter query called
MonthlySalary_FinalQuery_TASK_TOTALS
I have set this query and its parameters in vba as follows:
PHP:
'set main MonthlySal query
Set qdf_monthsal = CurrentDb.QueryDefs!MonthlySalary_FinalQuery_TASK_TOTALS
'parameters:
qdf_monthsal.Parameters![start date] = Forms!MonthlyReportForm.Reportstartdate
qdf_monthsal.Parameters![end date] = Forms!MonthlyReportForm.Reportstartdate
qdf_monthsal.Parameters![select FTE month] = Forms!MonthlyReportForm.MonthFTE
Now, I need to query this query based on conditions in a loop, which loops throgh another recordset of subtasks and sets the name of the current subtask to variable currentsubtask. I am trying to accomplish this 're-querying' of the original query by setting up another recordset based on a sql string as follows:
PHP:
Dim SQL_TOTALS_reg_subtask
SQL_TOTALS_reg_subtask = "Select * from " & qdf_monthsal & " where ServiceSubcat like '" & currenttask & "';"
Dim rs_subtasks As DAO.Recordset
Set rs_subtasks = CurrentDb.OpenRecordset(SQL_subtasks, dbOpenSnapshot)
When I try to compile, I get a 'Type mismatch' error. I realize that it is probably wrong to use the queryDef which defined the original query as a query in itself, but I am not sure how else to re-query the queryDef. Should I just put the original query in vba as a sql string and apply the currenttask condition right there? I was trying to avoid that since
MonthlySalary_FinalQuery_TASK_TOTALS is a really long sql statement and it would be a pain in the neck to format it with all the "" and &'s in the vba window.
Can anyone suggest an easy way to combine a querydef and sql string in vba? Any help would be greatly appreciated!