I have created a routine, based on help from here, to export table results to Excel. The code seems to work fine. It sends the correct results to excel 100% of the time but sometimes (and it is completely random) A quick pop-up occurs saying "Microsoft Office Excel has stopped working. Windows is checking for a solution to the problem"
It happens so fast that I had to to do a screen capture to see what the message said. Now here is what I do not understand...the results are correct. My code opens a pipe to excel sends the results and then closes it. There must be something missing in the code.
Please review the code and tell me where I went wrong.
Dim QryName As String
Dim xlApp As Object, xlWb As Object
If Me.frmViewGutsChild!PayeeID.ColumnHidden = False Then
QryName = "tblTC_Summary_details"
QryName = "tblTC_Summary_no_details"
DoCmd.OutputTo acOutputTable, QryName, acFormatXLS, strDT
Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Open(strDT)
.Worksheets(QryName).Name = "TC_Summary"
Set xlWb = Nothing
Set xlApp = Nothing