Hi All,
I recently ran into a problem with closing excel. This code has worked for over a year running 5 times a day with no problem. Recently Mircosoft office and XP SP3 updates came through on my PC. Now the code will not close my excel process.
I am using Access 2007 and Windows XP SP3
Thanks,
Kirk
Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection
Dim MyRecordset As New ADODB.Recordset
Dim MyRecordset2 As New ADODB.Recordset
MyRecordset.ActiveConnection = cnn
Dim MySQL As String
Dim MySQL2 As String
DoCmd.SetWarnings True
MySQL = "Select * FROM [DPC Completed Forecast];"
MyRecordset.Open MySQL
Dim MySheetPath As String
MySheetPath = "T:\Database\DPC\Completed DPC Forecast.xlsx"
'MySheetPath = MySheetPath + "\Sheet1.xls"
Dim X1 As Excel.Application
Dim X1Book As Excel.Workbook
Dim X1Sheet As Excel.Worksheet
Set X1 = CreateObject("Excel.Application")
Set X1Book = GetObject(MySheetPath)
X1.Visible = True
X1Book.Windows(1).Visible = True
Set X1Sheet = X1Book.Worksheets(1)
X1Sheet.Range("A2", "D1000").Clear
X1Sheet.Range("A2").CopyFromRecordset MyRecordset
X1.ActiveWorkbook.Save
X1.Quit
MyRecordset.Close
Set cnn = Nothing
Set X1 = Nothing
Set X1Sheet = Nothing
DoCmd.Hourglass False
'DoCmd.CloseDatabase
DoCmd.Quit
End Sub
I recently ran into a problem with closing excel. This code has worked for over a year running 5 times a day with no problem. Recently Mircosoft office and XP SP3 updates came through on my PC. Now the code will not close my excel process.
I am using Access 2007 and Windows XP SP3
Thanks,
Kirk
Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection
Dim MyRecordset As New ADODB.Recordset
Dim MyRecordset2 As New ADODB.Recordset
MyRecordset.ActiveConnection = cnn
Dim MySQL As String
Dim MySQL2 As String
DoCmd.SetWarnings True
MySQL = "Select * FROM [DPC Completed Forecast];"
MyRecordset.Open MySQL
Dim MySheetPath As String
MySheetPath = "T:\Database\DPC\Completed DPC Forecast.xlsx"
'MySheetPath = MySheetPath + "\Sheet1.xls"
Dim X1 As Excel.Application
Dim X1Book As Excel.Workbook
Dim X1Sheet As Excel.Worksheet
Set X1 = CreateObject("Excel.Application")
Set X1Book = GetObject(MySheetPath)
X1.Visible = True
X1Book.Windows(1).Visible = True
Set X1Sheet = X1Book.Worksheets(1)
X1Sheet.Range("A2", "D1000").Clear
X1Sheet.Range("A2").CopyFromRecordset MyRecordset
X1.ActiveWorkbook.Save
X1.Quit
MyRecordset.Close
Set cnn = Nothing
Set X1 = Nothing
Set X1Sheet = Nothing
DoCmd.Hourglass False
'DoCmd.CloseDatabase
DoCmd.Quit
End Sub