R
RocketDude
Hi,
I want to create a table in a subroutine in VBA using the Select ... Into
construct, but I keep getting "Run-time error '3067': Query input must
contain at least one table or query" for the following setup:
Public Sub DoSQL()
Dim SQL As String
SQL = "SELECT [NetSales].Brand, [NetSales].Distributor," & _
"([NetSales]![Jan02]+[NetSales]![Feb02]+[NetSales]![Mar02]+[NetSales]![Apr02]+[NetSales]![May02]+[NetSales]![Jun02]+[NetSales]![Jul02]+[NetSales]![Aug02]+[NetSales]![Sept02]+[NetSales]![Oct02]+[NetSales]![Nov02]+[NetSales]![Dec02])
AS 2002," & _
"([NetSales]![Jan03]+[NetSales]![Feb03]+[NetSales]![Mar03]+[NetSales]![Apr03]+[NetSales]![May03]+[NetSales]![Jun03]+[NetSales]![Jul03]+[NetSales]![Aug03]+[NetSales]![Sept03]+[NetSales]![Oct03]+[NetSales]![Nov03]+[NetSales]![Dec03])
AS 2003," & _
"([NetSales]![Jan04]+[NetSales]![Feb04]+[NetSales]![Mar04]+[NetSales]![Apr04]+[NetSales]![May04]+[NetSales]![Jun04]+[NetSales]![Jul04]+[NetSales]![Aug04]+[NetSales]![Sept04]+[NetSales]![Oct04]+[NetSales]![Nov04]+[NetSales]![Dec04])
AS 2004" & _
" INTO tblNetSalesYr" & _
"FROM (Distributor INNER JOIN (BrandCodes INNER JOIN [NetSales]
ON BrandCodes.Brand = [NetSales].Brand) ON Distributor.Distributor =
[NetSales].Distributor) INNER JOIN NetSales ON (BrandCodes.Brand =
NetSales.Brand) AND (Distributor.Distributor = NetSales.Distributor);"
DoCmd.RunSQL SQL
End Sub
"NetSales", "Distributor", "BrandCodes" are all tables.
The above SQL works correctly if I run it directly in Access as a query. All
help figuring out what is causing the above error will be greatly
appreciated.
TIA,
Matthew
I want to create a table in a subroutine in VBA using the Select ... Into
construct, but I keep getting "Run-time error '3067': Query input must
contain at least one table or query" for the following setup:
Public Sub DoSQL()
Dim SQL As String
SQL = "SELECT [NetSales].Brand, [NetSales].Distributor," & _
"([NetSales]![Jan02]+[NetSales]![Feb02]+[NetSales]![Mar02]+[NetSales]![Apr02]+[NetSales]![May02]+[NetSales]![Jun02]+[NetSales]![Jul02]+[NetSales]![Aug02]+[NetSales]![Sept02]+[NetSales]![Oct02]+[NetSales]![Nov02]+[NetSales]![Dec02])
AS 2002," & _
"([NetSales]![Jan03]+[NetSales]![Feb03]+[NetSales]![Mar03]+[NetSales]![Apr03]+[NetSales]![May03]+[NetSales]![Jun03]+[NetSales]![Jul03]+[NetSales]![Aug03]+[NetSales]![Sept03]+[NetSales]![Oct03]+[NetSales]![Nov03]+[NetSales]![Dec03])
AS 2003," & _
"([NetSales]![Jan04]+[NetSales]![Feb04]+[NetSales]![Mar04]+[NetSales]![Apr04]+[NetSales]![May04]+[NetSales]![Jun04]+[NetSales]![Jul04]+[NetSales]![Aug04]+[NetSales]![Sept04]+[NetSales]![Oct04]+[NetSales]![Nov04]+[NetSales]![Dec04])
AS 2004" & _
" INTO tblNetSalesYr" & _
"FROM (Distributor INNER JOIN (BrandCodes INNER JOIN [NetSales]
ON BrandCodes.Brand = [NetSales].Brand) ON Distributor.Distributor =
[NetSales].Distributor) INNER JOIN NetSales ON (BrandCodes.Brand =
NetSales.Brand) AND (Distributor.Distributor = NetSales.Distributor);"
DoCmd.RunSQL SQL
End Sub
"NetSales", "Distributor", "BrandCodes" are all tables.
The above SQL works correctly if I run it directly in Access as a query. All
help figuring out what is causing the above error will be greatly
appreciated.
TIA,
Matthew