Now that I've added this error handling code, when I export to Excel it flashes up on screen then quickly disappears. If I comment out the new code, the Excel export works fine. What gives? This works in Access.
After I dimmed my variables, I wrote this:
VB Code:
On Error GoTo CreateExcelSH_Err
Then at the bottom of the sub I wrote this:
VB Code:
CreateExcelSH_Exit: Call LoadCaption(False) For i = 0 To UBound(objRSArray) If objRSArray(i).State = 1 Then objRSArray(i).Close End If Next i Erase objRSArray Erase xlChartArray Set xlSheet = Nothing Set xlBook = Nothing xlApp.DisplayAlerts = False xlApp.Quit xlApp.DisplayAlerts = True Set xlApp = Nothing Exit Sub CreateExcelSH_Err: Select Case Err.Number Case 1004 MsgBox "Excel cannot draw graphs due to a lack of data. Please contact the Protection MI team." Resume CreateExcelSH_Exit Case Else MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error!" Resume CreateExcelSH_Exit End Select
I'm pretty new at error handling so I really have no idea what I'm doing.




Reply With Quote