Results 1 to 4 of 4
  1. #1
    Dunro is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Location
    Toronto, Canada
    Posts
    39

    Unable to Step Through VBA code after some methods such as CopyFromRecordset (Excel)

    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...)

  2. #2
    dr91075 is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2013
    Posts
    22
    What, exactly, do you mean by "runs off on its own"? Have you tried holding down the Escape key?

  3. #3
    Dunro is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Location
    Toronto, Canada
    Posts
    39
    Quote Originally Posted by dr91075 View Post
    What, exactly, do you mean by "runs off on its own"? Have you tried holding down the Escape key?
    Basically, instead of moving down one line when I press F8 to step through, VBA keeps running the entire process (as if I pressed F5). The escape key doesn't help when you're trying to step through.

    Unfortunately, the above code seems to be behaving today so my issue must be something else not in the above code.

  4. #4
    dr91075 is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2013
    Posts
    22
    My mistake. I thought you were trying to find an error. I meant using the escape key instead of stepping through. Sorry I wasn't clear. I'm glad you got it worked out.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Unable to use WithEvents effectively like we use in Excel
    By vikasbhandari2 in forum Programming
    Replies: 1
    Last Post: 02-19-2013, 09:22 PM
  2. Unable to close Excel from Access 2007
    By Phred in forum Programming
    Replies: 4
    Last Post: 01-14-2012, 01:58 PM
  3. step and step proccess
    By toochic in forum Programming
    Replies: 5
    Last Post: 10-09-2011, 09:34 AM
  4. Is There a Way to Debug or Step Through VB code?
    By jeffbase34 in forum Programming
    Replies: 1
    Last Post: 05-28-2009, 08:14 PM
  5. Replies: 4
    Last Post: 04-29-2009, 04:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums