The below code dumps data from one table into another using the query: qry_rpt_data_for_ct_prep_tbl as the intermediary to do so. It works, except that I wanted to restrict the data based on user selection for the time period.
So, I put criteria in the query itself. But with this addition, it blows up, telling me too few parameters, highlighting the "Set rs" portion of code.
Is there something I can do to make this work, or do I have to put the criteria in the recordset query string? If so any help on the syntax required for the string to read the form date values from a (date input) text box is appreciated..
Public Sub Build_Cross_Tab_Prep()
'order of fields below in the openrecordset are important as the 'for' statement goes in order the fields appear..
Dim rs As Recordset
Dim j As Integer
Dim str_SQL_Goal As String
Set rs = CurrentDb.OpenRecordset("qry_rpt_data_for_ct_prep_tbl")
rs.MoveLast
rs.MoveFirst
If rs.RecordCount > 0 Then
Do While Not rs.EOF
Dim i As Integer
i = 1
For i = 1 To 24
Dim strSQL As String
strSQL = "INSERT INTO tbl_Rpt_Crosstab_Prep (STATE, DT_RPT, QT_RPT, YR_RPT, MetricName, MetricValue) VALUES ('" _
+ rs!STATE + "',#" + Format(rs!DT_RPT, "MM/DD/YYYY") + "#,'" + CStr(QuarterFromDate(rs!DT_RPT)) + "','" _
+ CStr(Format(rs!DT_RPT, "yyyy")) + "','" + rs.Fields(i).Name + "'," + CStr(rs.Fields(i).Value) + ")"
CurrentDb.Execute strSQL
Next i
rs.MoveNext
Loop
End If
So, I put criteria in the query itself. But with this addition, it blows up, telling me too few parameters, highlighting the "Set rs" portion of code.
Is there something I can do to make this work, or do I have to put the criteria in the recordset query string? If so any help on the syntax required for the string to read the form date values from a (date input) text box is appreciated..
Public Sub Build_Cross_Tab_Prep()
'order of fields below in the openrecordset are important as the 'for' statement goes in order the fields appear..
Dim rs As Recordset
Dim j As Integer
Dim str_SQL_Goal As String
Set rs = CurrentDb.OpenRecordset("qry_rpt_data_for_ct_prep_tbl")
rs.MoveLast
rs.MoveFirst
If rs.RecordCount > 0 Then
Do While Not rs.EOF
Dim i As Integer
i = 1
For i = 1 To 24
Dim strSQL As String
strSQL = "INSERT INTO tbl_Rpt_Crosstab_Prep (STATE, DT_RPT, QT_RPT, YR_RPT, MetricName, MetricValue) VALUES ('" _
+ rs!STATE + "',#" + Format(rs!DT_RPT, "MM/DD/YYYY") + "#,'" + CStr(QuarterFromDate(rs!DT_RPT)) + "','" _
+ CStr(Format(rs!DT_RPT, "yyyy")) + "','" + rs.Fields(i).Name + "'," + CStr(rs.Fields(i).Value) + ")"
CurrentDb.Execute strSQL
Next i
rs.MoveNext
Loop
End If