Im running this series of code, excel starts and quits as expected, athough its process remains in memory.
Am I not closing it out properly? Please help!
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim xlApp As Object
Dim path As String
Dim objXl As Excel.Application
Dim objWkb As Excel.Workbook
Dim objSht As Excel.Worksheet
Dim RCount As Integer
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryschedulegrabber"
DoCmd.SetWarnings True
path = "f:\forecast\stndrds\Schedule.xls"
Set db = CurrentDb
Set rs = db.OpenRecordset("schedule")
rs.MoveLast
rs.MoveFirst
RCount = rs.RecordCount
Set objXl = New Excel.Application
RCount = RCount + 7
With rs
.Edit
With objXl
objXl.Visible = True
Set objWkb = .Workbooks.Open(path)
Worksheets("Rawdata").Activate
For Counter = 6 To RCount Step 1
Index = Counter
.Range("A" & Index).Value = rs![Job Number]
.Range("B" & Index).Value = rs![Type]
.Range("C" & Index).Value = rs![RemainingPDR]
.Range("f" & Index).Value = rs![Shop Progress]
If rs![Type] = "A" Then .Range("D" & Index).Value = rs![Actual Production]
If rs![Type] = "P" Then .Range("D" & Index).Value = rs![Projected Construction]
.Range("E" & Index).Value = rs![EndDate]
rs.MoveNext
If rs.EOF Then
objWkb.Save
.Application.Quit
Set objWkb = Nothing
Set objXl = Nothing
Set objSht = Nothing
MsgBox "Data Transfer Complete!" & vbCrLf & "Click OK to Open Spreadsheet", vbInformation, "Complete!"
Shell "C:\program files\Microsoft office\office\excel.exe f:\forecast\stndrds\schedule.xls", vbMaximizedFocus
Exit Sub
End If
Next Counter
rs.Close
End With
End With
End Sub
Am I not closing it out properly? Please help!
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim xlApp As Object
Dim path As String
Dim objXl As Excel.Application
Dim objWkb As Excel.Workbook
Dim objSht As Excel.Worksheet
Dim RCount As Integer
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryschedulegrabber"
DoCmd.SetWarnings True
path = "f:\forecast\stndrds\Schedule.xls"
Set db = CurrentDb
Set rs = db.OpenRecordset("schedule")
rs.MoveLast
rs.MoveFirst
RCount = rs.RecordCount
Set objXl = New Excel.Application
RCount = RCount + 7
With rs
.Edit
With objXl
objXl.Visible = True
Set objWkb = .Workbooks.Open(path)
Worksheets("Rawdata").Activate
For Counter = 6 To RCount Step 1
Index = Counter
.Range("A" & Index).Value = rs![Job Number]
.Range("B" & Index).Value = rs![Type]
.Range("C" & Index).Value = rs![RemainingPDR]
.Range("f" & Index).Value = rs![Shop Progress]
If rs![Type] = "A" Then .Range("D" & Index).Value = rs![Actual Production]
If rs![Type] = "P" Then .Range("D" & Index).Value = rs![Projected Construction]
.Range("E" & Index).Value = rs![EndDate]
rs.MoveNext
If rs.EOF Then
objWkb.Save
.Application.Quit
Set objWkb = Nothing
Set objXl = Nothing
Set objSht = Nothing
MsgBox "Data Transfer Complete!" & vbCrLf & "Click OK to Open Spreadsheet", vbInformation, "Complete!"
Shell "C:\program files\Microsoft office\office\excel.exe f:\forecast\stndrds\schedule.xls", vbMaximizedFocus
Exit Sub
End If
Next Counter
rs.Close
End With
End With
End Sub