Good morning everyone. Time to time I face with the Error 3061 Too Few Parameters Expected 1. I tried to check around some solution but it seems i'm not able to solve. Below is my code. Mainly I have a table with a list of queries name (previous build based) and for each query i need:
1. Create a new Worksheet in the Summary Error Report (previously created) with the name of the Query;
2. Add records in the new worksheet with the result of the query.
The point 1 work fine, but as soon as i tried to read the records in the query (by the query name), it give me the error.
Set dba = CurrentDb()
Set rst = dba.OpenRecordset("tbl_QC_Result", dbOpenDynaset)
rst.MoveFirst
Do Until rst.EOF
If rst!Nr_Records > 0 Then
'Create a new worksheet with name of query
Dim ws As Worksheet
Set ws = oApp.ActiveWorkbook.Sheets.Add(After:=oApp.ActiveWorkbook.Sheets(oApp.ActiveWorkbook.Sheets.Count))
ws.Name = rst!Query_File_Name
Set rst_data = dba.OpenRecordset(rst!Query_Code, dbOpenDynaset) --------------> HERE I GET THE ERROR
'Write Eather
y = 1
With rst_data
While Not .EOF
For X = 0 To .Fields.Count - 1
oApp.ActiveWorkbook.ActiveSheet.Cells(y, X + 1) = .Fields(X).Name
Next X
.MoveNext
Wend
End With
rst_data.Close
Set rst_data = Nothing
'Write the records
Set rst_data = dba.OpenRecordset(rst!Query_Code, dbOpenDynaset)
y = 2
With rst_data
While Not .EOF
For X = 0 To .Fields.Count - 1
oApp.ActiveWorkbook.ActiveSheet.Cells(y, X + 1) = .Fields(X).Value
Next X
y = y + 1
.MoveNext
Wend
End With
rst_data.Close
Set rst_data = Nothing
End If
oApp.ActiveWorkbook.ActiveSheet.Cells.EntireColumn.AutoFit
rst.MoveNext
Loop
oApp.ActiveWorkbook.Close SaveChanges:=True
Here is the SQL of the query i use (which give error) :
SELECT [05-EDW-DE].[PROJECT CODE], [05-EDW-DE].[TAG NAME], [05-EDW-DE].[PRODUCTION CRITICAL ITEM]
FROM [05-EDW-DE]
WHERE ((([05-EDW-DE].[PROJECT CODE]) Like [Forms]![frm_project_selection_for_edw_de_qc]![PRJ]) AND (([05-EDW-DE].[PRODUCTION CRITICAL ITEM])=""));
Any idea ?
Thank you in advance for kindly support.
Cheers
1. Create a new Worksheet in the Summary Error Report (previously created) with the name of the Query;
2. Add records in the new worksheet with the result of the query.
The point 1 work fine, but as soon as i tried to read the records in the query (by the query name), it give me the error.
Set dba = CurrentDb()
Set rst = dba.OpenRecordset("tbl_QC_Result", dbOpenDynaset)
rst.MoveFirst
Do Until rst.EOF
If rst!Nr_Records > 0 Then
'Create a new worksheet with name of query
Dim ws As Worksheet
Set ws = oApp.ActiveWorkbook.Sheets.Add(After:=oApp.ActiveWorkbook.Sheets(oApp.ActiveWorkbook.Sheets.Count))
ws.Name = rst!Query_File_Name
Set rst_data = dba.OpenRecordset(rst!Query_Code, dbOpenDynaset) --------------> HERE I GET THE ERROR
'Write Eather
y = 1
With rst_data
While Not .EOF
For X = 0 To .Fields.Count - 1
oApp.ActiveWorkbook.ActiveSheet.Cells(y, X + 1) = .Fields(X).Name
Next X
.MoveNext
Wend
End With
rst_data.Close
Set rst_data = Nothing
'Write the records
Set rst_data = dba.OpenRecordset(rst!Query_Code, dbOpenDynaset)
y = 2
With rst_data
While Not .EOF
For X = 0 To .Fields.Count - 1
oApp.ActiveWorkbook.ActiveSheet.Cells(y, X + 1) = .Fields(X).Value
Next X
y = y + 1
.MoveNext
Wend
End With
rst_data.Close
Set rst_data = Nothing
End If
oApp.ActiveWorkbook.ActiveSheet.Cells.EntireColumn.AutoFit
rst.MoveNext
Loop
oApp.ActiveWorkbook.Close SaveChanges:=True
Here is the SQL of the query i use (which give error) :
SELECT [05-EDW-DE].[PROJECT CODE], [05-EDW-DE].[TAG NAME], [05-EDW-DE].[PRODUCTION CRITICAL ITEM]
FROM [05-EDW-DE]
WHERE ((([05-EDW-DE].[PROJECT CODE]) Like [Forms]![frm_project_selection_for_edw_de_qc]![PRJ]) AND (([05-EDW-DE].[PRODUCTION CRITICAL ITEM])=""));
Any idea ?
Thank you in advance for kindly support.
Cheers