J
Jim S
When I run the following code, I get "Run - Time Error
3061" "Too Few parameters" The code creates the make -
table query, but gives the error when the code tries to
execute the query and create the table. (Running the
query manually creates the table)
I have created many tables with code in then past with
few problems.
Any idea how get this query to execute by using code?
Jim
Sub CreateTb1()
'Create a SQL Make Table Query
'Create Table1 - Table of locations in the selected
records
Dim db As Database
Dim qdf As QueryDef
Dim A As String, B As String, C As String
Dim D As String, E As String, F As String
Dim G As String, H As String, I As String
Dim J As String, K As String, L As String
Dim M As String, N As String, O As String
Dim P As String
Dim QrySQL As String
'Pieces of SQL Statment
A = "SELECT qry_RawData.Location INTO Temp1"
B = "FROM qry_RawData"
C = "GROUP BY qry_RawData.Pedigree, qry_RawData.[Nesting
Group], qry_RawData.[EU Entry Number], qry_RawData.Rep,
qry_RawData.[EU Data Quality], qry_RawData.[EU SPPLOT
(list)], qry_RawData.[Expt Name],"
D = "qry_RawData.Location, qry_RawData.[Location Site
Code], qry_RawData.[EU Inventory ID], qry_RawData.[EU
Source Name], qry_RawData.[Site Short Name]"
E = "HAVING (((qry_RawData.Pedigree) Like "
F = " & [Forms]![frm_Main]![Combo6] & "
G = ") AND ((qry_RawData.[Nesting Group]) Like "
H = " & [Forms]![frm_Main]![Combo1] & "
I = ") AND ((qry_RawData.[EU Entry "
J = "Number])=[Forms]![frm_Main]![Combo16]) AND
((qry_RawData.Rep) Like "
K = " & [Forms]![frm_Main]![Combo18]) AND ((qry_RawData.
[EU Data Quality]) Like "
L = " & [Forms]![frm_Main]![Combo20]) AND ((qry_RawData.
[EU SPPLOT (list)])Like "
M = " & [Forms]![frm_Main]![Combo22]))"
N = "ORDER BY qry_RawData.[Nesting Group], qry_RawData.
[EU Entry Number], qry_RawData.Rep, qry_RawData.Location;"
O = A & Chr(10) & B & Chr(10) & C & D & Chr(10) & E & Chr
(34) & "*" & Chr(34) & F & Chr(34) & "*" & Chr(34) & G &
Chr(34) & "*" & Chr(34) & H & Chr(34) & "*" & Chr(34) & I
P = J & Chr(34) & "*" & Chr(34) & K & Chr(34) & "*" & Chr
(34) & L & Chr(34) & "*" & Chr(34) & M & Chr(10) & N
'Create SQL
QrySQL = O & P
'Create query
Set db = CurrentDb()
Set qdf = db.CreateQueryDef("qry_Temp1", QrySQL)
qdf.Execute
qdf.Close
db.Close
Set qdf = Nothing
'Delete Query "qry_Temp1"
'DoCmd.DeleteObject acQuery, "qry_Temp1"
End Sub
3061" "Too Few parameters" The code creates the make -
table query, but gives the error when the code tries to
execute the query and create the table. (Running the
query manually creates the table)
I have created many tables with code in then past with
few problems.
Any idea how get this query to execute by using code?
Jim
Sub CreateTb1()
'Create a SQL Make Table Query
'Create Table1 - Table of locations in the selected
records
Dim db As Database
Dim qdf As QueryDef
Dim A As String, B As String, C As String
Dim D As String, E As String, F As String
Dim G As String, H As String, I As String
Dim J As String, K As String, L As String
Dim M As String, N As String, O As String
Dim P As String
Dim QrySQL As String
'Pieces of SQL Statment
A = "SELECT qry_RawData.Location INTO Temp1"
B = "FROM qry_RawData"
C = "GROUP BY qry_RawData.Pedigree, qry_RawData.[Nesting
Group], qry_RawData.[EU Entry Number], qry_RawData.Rep,
qry_RawData.[EU Data Quality], qry_RawData.[EU SPPLOT
(list)], qry_RawData.[Expt Name],"
D = "qry_RawData.Location, qry_RawData.[Location Site
Code], qry_RawData.[EU Inventory ID], qry_RawData.[EU
Source Name], qry_RawData.[Site Short Name]"
E = "HAVING (((qry_RawData.Pedigree) Like "
F = " & [Forms]![frm_Main]![Combo6] & "
G = ") AND ((qry_RawData.[Nesting Group]) Like "
H = " & [Forms]![frm_Main]![Combo1] & "
I = ") AND ((qry_RawData.[EU Entry "
J = "Number])=[Forms]![frm_Main]![Combo16]) AND
((qry_RawData.Rep) Like "
K = " & [Forms]![frm_Main]![Combo18]) AND ((qry_RawData.
[EU Data Quality]) Like "
L = " & [Forms]![frm_Main]![Combo20]) AND ((qry_RawData.
[EU SPPLOT (list)])Like "
M = " & [Forms]![frm_Main]![Combo22]))"
N = "ORDER BY qry_RawData.[Nesting Group], qry_RawData.
[EU Entry Number], qry_RawData.Rep, qry_RawData.Location;"
O = A & Chr(10) & B & Chr(10) & C & D & Chr(10) & E & Chr
(34) & "*" & Chr(34) & F & Chr(34) & "*" & Chr(34) & G &
Chr(34) & "*" & Chr(34) & H & Chr(34) & "*" & Chr(34) & I
P = J & Chr(34) & "*" & Chr(34) & K & Chr(34) & "*" & Chr
(34) & L & Chr(34) & "*" & Chr(34) & M & Chr(10) & N
'Create SQL
QrySQL = O & P
'Create query
Set db = CurrentDb()
Set qdf = db.CreateQueryDef("qry_Temp1", QrySQL)
qdf.Execute
qdf.Close
db.Close
Set qdf = Nothing
'Delete Query "qry_Temp1"
'DoCmd.DeleteObject acQuery, "qry_Temp1"
End Sub