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
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