Hi everyone,
This may be a general or Excel VBA issue, but i'm posting here as my current dilemma is in Access.
I have an issue where sometimes my code runs off "on its own" when I'm trying to step through it. I know it's because I'm doing aomething wrong, and would like to learn more but have no idea what I'm actually looking for.
I stop the code using breakpoints as well as using Control+Break. When I step through, the code "runs on its own" and won't allow me to break after I hit certain methods. (I've had the issue with Excel macros as well...).
Here is a simplified example:
Code:
Option Explicit
Private objExcel As Excel.Application
Private objWrkSht As Excel.Worksheet
Public Sub exampleExport(queryDefinitonText As String)
On Error GoTo Exit_Error
Dim rstReport As Recordset
Set objExcel = New Excel.Application
objExcel.Visible = True
Set objWrkSht = objExcel.Workbooks.Add.Sheets(1)
objWrkSht.Activate
Set rstReport = CurrentDb.OpenRecordset(queryDefinitonText)
objWrkSht.Range("A2").CopyFromRecordset rstReport ' *** can't break or step after this line ***
rstReport.Close
Set rstReport = Nothing
Set objExcel = Nothing
Exit Sub
Exit_Error:
Debug.Print "Error detected."
End Sub
Any ideas why it's going berserk? (I realize TransferSpreadsheet is a preferred method based on this example, but this code ultimately fits into something larger...)