jfgambit
Kinetic Card Dealer
- Local time
- Today, 21:05
- Joined
- Jul 18, 2002
- Messages
- 798
I have code that exports a Query to Excel via VB Code. I was hoping that someone knows of code to add rows in Excel to the beginning(2 Rows) and end of the export(1 Row). I have attached an example of what the final export needs to look like in Excel once completed and below is the code. Additionally, the header rows do not need to export from the query.
Thanks for any help!!
Export Code:
Function ExportSCACOTR()
Dim MyRS As DAO.Recordset
Dim SCACcd As String
Dim MyStr As String
Dim MyQD As QueryDef
txDate = Format(Date, "mmddyy")
'Open query that Groups each individual SCAC code
'Open the query that pulls the On Time Performance information for each Carrier
Set MyRS = CurrentDb.OpenRecordset("qryCarrierSCACGrouping")
Set MyQD = CurrentDb.QueryDefs("qryCarrierExportModule")
'Move to the first SCAC
MyRS.MoveFirst
SCACcd = MyRS("SCAC")
'Select the information based on the SCAC selected by MyRS
MyStr = ("SELECT * from [tempDataExport] where SCAC = '" & SCACcd & "';")
MyQD.SQL = MyStr
'Export the information to an Excel sheet
DoCmd.OutputTo acOutputQuery, "qryCarrierExportModule", "MicrosoftExcel(*.xls)", "C:\Transportation\OTR_" & SCACcd & "_" & txDate & ".xls"
'Close the queries
MyRS.Close
MyQD.Close
End Function
Thanks for any help!!
Export Code:
Function ExportSCACOTR()
Dim MyRS As DAO.Recordset
Dim SCACcd As String
Dim MyStr As String
Dim MyQD As QueryDef
txDate = Format(Date, "mmddyy")
'Open query that Groups each individual SCAC code
'Open the query that pulls the On Time Performance information for each Carrier
Set MyRS = CurrentDb.OpenRecordset("qryCarrierSCACGrouping")
Set MyQD = CurrentDb.QueryDefs("qryCarrierExportModule")
'Move to the first SCAC
MyRS.MoveFirst
SCACcd = MyRS("SCAC")
'Select the information based on the SCAC selected by MyRS
MyStr = ("SELECT * from [tempDataExport] where SCAC = '" & SCACcd & "';")
MyQD.SQL = MyStr
'Export the information to an Excel sheet
DoCmd.OutputTo acOutputQuery, "qryCarrierExportModule", "MicrosoftExcel(*.xls)", "C:\Transportation\OTR_" & SCACcd & "_" & txDate & ".xls"
'Close the queries
MyRS.Close
MyQD.Close
End Function