The following snippet works fine :
... except that the same TrackingNumber may (rarely) be shared by two or more SalesRecords (where two sales are combined into one package for shipping to the customer). In that case, I only want the customer and tracking number to appear once in the resultant spreadsheet.
The following works to get unique TrackingNumbers
- should I somehow incorporate that as a subquery ?
By the way, OpenArgs contains a string such as
Code:
strSQL = "SELECT Customers.CustomerName & ', ' & Customers.AddressLine1 & ', '" & _
" & Customers.Addressline2 & ', ' & Customers.City & ', ' & Customers.StateOrCounty & ', '" & _
" & Customers.ZipOrPostcode, SalesRecords.TrackingNumber, SalesRecords.Paid FROM SalesRecords" & _
" INNER JOIN Customers ON SalesRecords.fkCustomerID = Customers.CustomerID WHERE " & OpenArgs
Debug.Print strSQL
db.CreateQueryDef "qryTest", strSQL
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qryTest", _
"C:\Users\" & Environ("username") & "\desktop\Test"
db.QueryDefs.Delete "qryTest"
... except that the same TrackingNumber may (rarely) be shared by two or more SalesRecords (where two sales are combined into one package for shipping to the customer). In that case, I only want the customer and tracking number to appear once in the resultant spreadsheet.
The following works to get unique TrackingNumbers
Code:
strSQL = "SELECT DISTINCT SalesRecords.TrackingNumber FROM SalesRecords WHERE " & OpenArgs
By the way, OpenArgs contains a string such as
Code:
Courier = 'RM Signed for' AND SaleDate >= #30/11/2015# AND Not IsNull(DateShipped)