jfgambit
Kinetic Card Dealer
- Local time
- Today, 15:52
- Joined
- Jul 18, 2002
- Messages
- 798
Hello All:
I've drawn a blank and for some reason can't get my code for exporting out records to multiple excel sheets to work. The code is as follows:
My error keeps coming up in the bolded WHERE Statement. Can anyone see what I'm missing, I know it has got to be something simple.
I've drawn a blank and for some reason can't get my code for exporting out records to multiple excel sheets to work. The code is as follows:
Code:
Dim MyRS As Recordset
Dim SID As String
Dim MyQD As QueryDef
Dim StDt As Date
Dim EdDt As Date
Dim MyStr As Variant
SetWarnings = False
StDt = InputBox("What is Start Date?", "Commission Export Start Date")
EdDt = InputBox("What is End Date?", "Commission Export End Date")
Set MyRS = CurrentDb.OpenRecordset("SELECT tblSAPBookings.[Sales Rep] FROM tblSAPBookings WHERE (((tblSAPBookings.OrderDate) Between " & StDt & " AND " & EdDt & ")) GROUP BY tblSAPBookings.[Sales Rep];")
Set MyQD = CurrentDb.OpenRecordset("SELECT tblSAPBookings.[Sales Rep], tblSAPBookings.[Sales ID], tblSAPBookings.[End User], tblSAPBookings.[End Name], tblSAPBookings.Qty, tblSAPBookings.[Unit Price], tblSAPBookings.[EXT Price], tblSAPBookings.[ZIP Code], tblSAPBookings.State, tblSAPBookings.Country, tblSAPBookings.[Order #], tblSAPBookings.[PO #], tblSAPBookings.[Part #], tblSAPBookings.Desc, tblProductHeirarchy.ProdCommCatagory, tblSAPBookings.OrderDate, tblSAPBookings.PCR, tblSAPBookings.CommPayment " & vbNewLine _
& "FROM tblSAPBookings LEFT JOIN tblProductHeirarchy ON tblSAPBookings.[Prod Hier] = tblProductHeirarchy.ProductHierarchy " & vbNewLine _
& "GROUP BY tblSAPBookings.[Sales Rep], tblSAPBookings.[Sales ID], tblSAPBookings.[End User], tblSAPBookings.[End Name], tblSAPBookings.Qty, tblSAPBookings.[Unit Price], tblSAPBookings.[EXT Price], tblSAPBookings.[ZIP Code], tblSAPBookings.State, tblSAPBookings.Country, tblSAPBookings.[Order #], tblSAPBookings.[PO #], tblSAPBookings.[Part #], tblSAPBookings.Desc, tblProductHeirarchy.ProdCommCatagory, tblSAPBookings.OrderDate, tblSAPBookings.PCR, tblSAPBookings.CommPayment " & vbNewLine _
[B]& "WHERE (tblSAPBookings.OrderDate) Between #" & StDt & "# AND #" & EdDt & "#;")[/B]
'Move to first Sale ID
MyRS.MoveFirst
Do
SID = MyRS("Sales Rep")
'Select the Commission data based on the SaleId selected by MyRS
MyStr = MyQD
DoCmd.OutputTo acOutputQuery, MyStr, "MicrosoftExcel(*.xls)", "C:\Finance\Commssions\CommissionDocs\" & SID & Format(Date, "MM") & Format(Date, "YYYY") & ".xls"
'Move to Next record and Loop until EOF
MyRS.MoveNext
Loop Until MyRS.EOF = True
MyRS.Close
MyQD.Close
SetWarnings = True
My error keeps coming up in the bolded WHERE Statement. Can anyone see what I'm missing, I know it has got to be something simple.