jfgambit
Kinetic Card Dealer
- Local time
- Today, 22:26
- Joined
- Jul 18, 2002
- Messages
- 798
I have a table that has multiple line information for Carriers. I need to export an individual Excel sheet for each carrier based on their SCAC Code. I have 2 queries: the first pulls the individual SCAC Codes the second pulls all the information to be transferred to the Excel sheet. I have the below code (which I got from this great forum) in a Public Function, but every time I run it through a Macro I get the following message "Circular reference caused by 'qryCarrierExportModule'.
When I run the debugger it highlights the following line: DoCmd.OutputTo acOutputQuery, "qryCarrierExportModule", "MicrosoftExcel(*.xls)", "C:\Documents and Settings\jfrick\My Documents\OnTime Rpts\OTR_" & SCACcd & "_" & txDate & ".xls"
Can anyone see why...I'm stumped! Or if you have code that you believe is better than the below, can you pass it on.
As an additional FYI, I changed the Do.cmd to:
DoCmd.TransferSpreadsheet, acSpreadsheetTypeExcel97, "qryCarrierExportModule", "C:\Documents and Settings\jfrick\My Documents\OnTime Rpts\OTR_" & SCACcd & "_" & txDate & ".xls"
But unfortunately I get Runtime Error '3011':
"The Microsoft Jet Enginee could not find the object C:\Documents and Settings\jfrick\My Documents\OnTime Rpts\OTR_0000_071902 .Make sure the object exists and that you spelled its path correclty." (And yes I have checked the spelling and ensured that all the folders are there).
Code:
Function ExportSCACOTR()
Dim MyRS As Recordset
Dim SCACcd As String
Dim MyStr As String
Dim MyQD As QueryDef
txDate = Format(Date, "mmddyy")
Set MyRS = CurrentDb.OpenRecordset("qryCarrierSCACGrouping")
Set MyQD = CurrentDb.QueryDefs("qryCarrierExportModule")
MyRS.MoveFirst
Do
SCACcd = MyRS("SCAC")
MyStr = ("SELECT * from [qryCarrierExportModule] where [SCAC] = " & SCACcd & "")
MyQD.SQL = MyStr
DoCmd.OutputTo acOutputQuery, "qryCarrierExportModule", "MicrosoftExcel(*.xls)", "C:\Documents and Settings\jfrick\My Documents\OnTime Rpts\OTR_" & SCACcd & "_" & txDate & ".xls"
MyRS.MoveNext
Loop Until MyRS.EOF = True
MyRS.Close
MyQD.Close
End Function
When I run the debugger it highlights the following line: DoCmd.OutputTo acOutputQuery, "qryCarrierExportModule", "MicrosoftExcel(*.xls)", "C:\Documents and Settings\jfrick\My Documents\OnTime Rpts\OTR_" & SCACcd & "_" & txDate & ".xls"
Can anyone see why...I'm stumped! Or if you have code that you believe is better than the below, can you pass it on.
As an additional FYI, I changed the Do.cmd to:
DoCmd.TransferSpreadsheet, acSpreadsheetTypeExcel97, "qryCarrierExportModule", "C:\Documents and Settings\jfrick\My Documents\OnTime Rpts\OTR_" & SCACcd & "_" & txDate & ".xls"
But unfortunately I get Runtime Error '3011':
"The Microsoft Jet Enginee could not find the object C:\Documents and Settings\jfrick\My Documents\OnTime Rpts\OTR_0000_071902 .Make sure the object exists and that you spelled its path correclty." (And yes I have checked the spelling and ensured that all the folders are there).
Code:
Function ExportSCACOTR()
Dim MyRS As Recordset
Dim SCACcd As String
Dim MyStr As String
Dim MyQD As QueryDef
txDate = Format(Date, "mmddyy")
Set MyRS = CurrentDb.OpenRecordset("qryCarrierSCACGrouping")
Set MyQD = CurrentDb.QueryDefs("qryCarrierExportModule")
MyRS.MoveFirst
Do
SCACcd = MyRS("SCAC")
MyStr = ("SELECT * from [qryCarrierExportModule] where [SCAC] = " & SCACcd & "")
MyQD.SQL = MyStr
DoCmd.OutputTo acOutputQuery, "qryCarrierExportModule", "MicrosoftExcel(*.xls)", "C:\Documents and Settings\jfrick\My Documents\OnTime Rpts\OTR_" & SCACcd & "_" & txDate & ".xls"
MyRS.MoveNext
Loop Until MyRS.EOF = True
MyRS.Close
MyQD.Close
End Function