Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Macro getting a error code

Status
Not open for further replies.

jfgambit

Programmer
Jul 15, 2002
240
0
0
US
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 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!

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


 
I'm not quite sure I get all that you're doing, but assuming the rest of your code is right, shouldn't you be using:

DoCmd.TransferSpreadsheet rather than DoCmd.OutputTo?

DoCmd.TransferSpreadsheet, acSpreadsheetTypeExcel97, "qryCarrierExportModule", "C:\Documents and Settings\jfrick\My Documents\OnTime Rpts\OTR_" & SCACcd & "_" & txDate & ".xls"

Bev
 
Bev:
I have tried that, 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.

Any ideas why??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top