graviz
Registered User.
- Local time
- Today, 09:58
- Joined
- Aug 4, 2009
- Messages
- 167
I wrote this code in Access 2003 and now I'm in 2007 and it's giving me a 1004 error Method of Save of object failed (XlBook.Save). I checked the refs and everything seems to be fine. Any ideas?
Code:
Public Function Output_Overall()
Call Init_Paths
Dim cnn As ADODB.Connection
Dim MyRecordset As New ADODB.Recordset
Dim MySQL As String
Dim MySheetPath As String
Dim Xl As Excel.Application
Dim XlBook As Excel.Workbook
Dim XlSheet As Excel.Worksheet
Set cnn = CurrentProject.Connection
MyRecordset.ActiveConnection = cnn
MySQL = "SELECT * From "
MySQL = MySQL & "02_08_Overall_Latest_Week"
MyRecordset.Open MySQL
MySheetPath = Staging_Path
Set Xl = CreateObject("Excel.Application")
Set XlBook = GetObject(MySheetPath)
Xl.Visible = True
XlBook.Windows(1).Visible = True
Set XlSheet = XlBook.Worksheets("Overall")
For iCol = 1 To MyRecordset.Fields.Count
XlSheet.Cells(1, iCol).Value = MyRecordset.Fields(iCol - 1).Name
Next
XlSheet.Range("A2").CopyFromRecordset MyRecordset
MyRecordset.Close
Set cnn = Nothing
Set Xl = Nothing
XlBook.Save
XlBook.Close
Set XlBook = Nothing
Set XlSheet = Nothing
End Function