View Full Version : Disconnects to Excel


JimLecocq
12-10-2007, 06:01 AM
I did some searching but could not find a direct illustration of this.

I am trying to run a query, push it to Excel using acoutputQuery but that creates a connection between the query or database and Excel. I then need to open it to edit but it is lock up, it seems, by the database.

I have used Excel.application.quit and that seems to help but there still seems to be some problems. If I have any other problems it locks up and the only way to clear it that I have found is by killing it with Process Explorer.

What I need to do is reopen it and make other edits through VBA.

Any one have any immediate insight to my problem?

I would not recommend trying to run this unless you have Process Explorer.

Code at present:

Dim objExcel As Excel.Application, xlWB As Workbook, xlWS As Worksheet

Dim xlwb1 As String

Dim iday As Integer
Dim iMon As Integer
Dim sMon As String


iday = Day(Date)
iMon = Month(Date)
sMon = MonthName(iMon, True)

Set objExcel = New Excel.Application
Set xlWB = objExcel.Workbooks.Add


On Error GoTo SpreadsheetQuery_Err

Workbooks.Add

ActiveWorkbook.SaveAs "c:\DBTesting\Excelquery_" & sMon & "-" & iday & ".xls"
Excel.Application.Quit

DoCmd.OutputTo acOutputQuery, "qsel_Inst_Dollars", acFormatXLS, "C:\DBTesting\Excelquery_" & sMon & "-" & iday & ".xls"
Excel.Application.Quit



Workbooks.Open "c:\DBTesting\Excelquery_" & sMon & "-" & iday & ".xls"
Columns("A:B").Select
Selection.Insert Shift:=xlToRight

Excel.Application.Quit

SpreadsheetQuery_Exit:
Exit Sub

SpreadsheetQuery_Err:
MsgBox Error$
Resume SpreadsheetQuery_Exit

End Sub

JimLecocq
12-10-2007, 09:01 AM
Sorry all. Found several possible solutions in "Similar Threads" below.

JimLecocq
12-10-2007, 09:04 AM
I can post the threads if anyone needs them. However, the Thead name was "Access & Excel"