J
Joe W
Hello,
I want to convert some of the queries I built in the Access
Query Builder to VBA modules. I have quite a few nested
queries. How can I convert these to VBA modules?
Below is the SQL code for two of the queries. These are
part of a small book sales reporting database. The first
one is for "query 1," the "baseline" query that extracts
data only from tables.
The second SQL example is for a query called "2004 BUSINESS
SUMMARY" that draws data from Query 1.
Thank you for help.
------------------------------------------
SQL CODE FOR QUERY 1
SELECT [Order-line linked table].[price-categ],
pro1_constit.[sort-name], [Order-line linked table].isbn,
[Order-line linked table].description, Sum([Order-line
linked table].amount) AS Sales, Sum([Order-line linked
table].[order-qty]) AS Quantity, [Customer Price
Categories].Field2 AS Category, "6/30/2004" AS
ReportPeriod, [Order-line linked table].["invoice-date"],
pro1_constit.[constit-id], [All Books_1].Title, IIf([All
Books_1]!Title=Null,[Order-line linked
table]![description],[All Books_1]!Title) AS ExpandedTitle,
[All Books_1].[Hard/Soft], [All Books_1].Price, [Order-line
linked table].[promo-code], [Order-line linked
table].[order-type]
FROM (([Order-line linked table] INNER JOIN [Customer Price
Categories] ON [Order-line linked table].[price-categ] =
[Customer Price Categories].Field1) LEFT JOIN pro1_constit
ON [Order-line linked table].[cust-number] =
pro1_constit.[constit-id]) LEFT JOIN [All Books] AS [All
Books_1] ON [Order-line linked table].[item-number] = [All
Books_1].[APA Item Number]
GROUP BY [Order-line linked table].[price-categ],
pro1_constit.[sort-name], [Order-line linked table].isbn,
[Order-line linked table].description, [Customer Price
Categories].Field2, "6/30/2004", [Order-line linked
table].["invoice-date"], pro1_constit.[constit-id], [All
Books_1].Title, IIf([All Books_1]!Title=Null,[Order-line
linked table]![description],[All Books_1]!Title), [All
Books_1].[Hard/Soft], [All Books_1].Price, [Order-line
linked table].[promo-code], [Order-line linked
table].[order-type]
HAVING (((pro1_constit.[sort-name]) Not Like "*Do Not Use")
AND (([Order-line linked
table].["invoice-date"])>=#1/1/2004# And ([Order-line
linked table].["invoice-date"])<=#6/30/2004#) AND
((pro1_constit.[constit-id])<>"46525090" And
(pro1_constit.[constit-id])<>"46806705") AND (([Order-line
linked table].[promo-code])<>"COMP-SO") AND (([Order-line
linked table].[order-type])="C"))
ORDER BY [Order-line linked table].[price-categ],
pro1_constit.[sort-name], [Order-line linked
table].description, [All Books_1].Title;
------------------------------------------------------
SQL CODE FOR QUERY "2004 BUSINESS SUMMARY"
SELECT Query1.[price-categ], Query1.[sort-name],
Query1.isbn, Query1.ExpandedTitle, Sum(Query1.Sales) AS
SumOfSales, Sum(Query1.Quantity) AS SumOfQuantity,
Query1.Category, Query1.ReportPeriod, Query1.[Hard/Soft]
FROM Query1
GROUP BY Query1.[price-categ], Query1.[sort-name],
Query1.isbn, Query1.ExpandedTitle, Query1.Category,
Query1.ReportPeriod, Query1.[Hard/Soft]
HAVING (((Query1.[sort-name]) Not Like "*Do Not Use"))
ORDER BY Query1.[price-categ], Query1.[sort-name],
Query1.ExpandedTitle;
I want to convert some of the queries I built in the Access
Query Builder to VBA modules. I have quite a few nested
queries. How can I convert these to VBA modules?
Below is the SQL code for two of the queries. These are
part of a small book sales reporting database. The first
one is for "query 1," the "baseline" query that extracts
data only from tables.
The second SQL example is for a query called "2004 BUSINESS
SUMMARY" that draws data from Query 1.
Thank you for help.
------------------------------------------
SQL CODE FOR QUERY 1
SELECT [Order-line linked table].[price-categ],
pro1_constit.[sort-name], [Order-line linked table].isbn,
[Order-line linked table].description, Sum([Order-line
linked table].amount) AS Sales, Sum([Order-line linked
table].[order-qty]) AS Quantity, [Customer Price
Categories].Field2 AS Category, "6/30/2004" AS
ReportPeriod, [Order-line linked table].["invoice-date"],
pro1_constit.[constit-id], [All Books_1].Title, IIf([All
Books_1]!Title=Null,[Order-line linked
table]![description],[All Books_1]!Title) AS ExpandedTitle,
[All Books_1].[Hard/Soft], [All Books_1].Price, [Order-line
linked table].[promo-code], [Order-line linked
table].[order-type]
FROM (([Order-line linked table] INNER JOIN [Customer Price
Categories] ON [Order-line linked table].[price-categ] =
[Customer Price Categories].Field1) LEFT JOIN pro1_constit
ON [Order-line linked table].[cust-number] =
pro1_constit.[constit-id]) LEFT JOIN [All Books] AS [All
Books_1] ON [Order-line linked table].[item-number] = [All
Books_1].[APA Item Number]
GROUP BY [Order-line linked table].[price-categ],
pro1_constit.[sort-name], [Order-line linked table].isbn,
[Order-line linked table].description, [Customer Price
Categories].Field2, "6/30/2004", [Order-line linked
table].["invoice-date"], pro1_constit.[constit-id], [All
Books_1].Title, IIf([All Books_1]!Title=Null,[Order-line
linked table]![description],[All Books_1]!Title), [All
Books_1].[Hard/Soft], [All Books_1].Price, [Order-line
linked table].[promo-code], [Order-line linked
table].[order-type]
HAVING (((pro1_constit.[sort-name]) Not Like "*Do Not Use")
AND (([Order-line linked
table].["invoice-date"])>=#1/1/2004# And ([Order-line
linked table].["invoice-date"])<=#6/30/2004#) AND
((pro1_constit.[constit-id])<>"46525090" And
(pro1_constit.[constit-id])<>"46806705") AND (([Order-line
linked table].[promo-code])<>"COMP-SO") AND (([Order-line
linked table].[order-type])="C"))
ORDER BY [Order-line linked table].[price-categ],
pro1_constit.[sort-name], [Order-line linked
table].description, [All Books_1].Title;
------------------------------------------------------
SQL CODE FOR QUERY "2004 BUSINESS SUMMARY"
SELECT Query1.[price-categ], Query1.[sort-name],
Query1.isbn, Query1.ExpandedTitle, Sum(Query1.Sales) AS
SumOfSales, Sum(Query1.Quantity) AS SumOfQuantity,
Query1.Category, Query1.ReportPeriod, Query1.[Hard/Soft]
FROM Query1
GROUP BY Query1.[price-categ], Query1.[sort-name],
Query1.isbn, Query1.ExpandedTitle, Query1.Category,
Query1.ReportPeriod, Query1.[Hard/Soft]
HAVING (((Query1.[sort-name]) Not Like "*Do Not Use"))
ORDER BY Query1.[price-categ], Query1.[sort-name],
Query1.ExpandedTitle;