+ Reply to Thread
Results 1 to 2 of 2

VBA error during execution at Exit Sub

Hybrid View

  1. #1
    Registered User
    Join Date
    06-29-2005
    Location
    Boston, MA
    Posts
    56

    VBA error during execution at Exit Sub

    I don't quite understand this error, there is no error trapping, but the vb code stops at "Exit Sub"
    The SQL statement is going against a SQLSERVER 2012 and I have never had this problem before. . as I copied this code from another working excel spreadsheet.


    Public Sub BillablePY(ByVal EndPeriod As Long)
    On Error GoTo Err_BillablePY
        
    Application.ODBCTimeout = 6000
         
    strSQL = "SELECT dist.Location_Name, sfa.Promo_Code, sfa.NA_Description, " & _
        "Sum(IIf(prd.Market='Product1',bil.Billed*fx.FXRate,0)), Sum(IIf(prd.Market='Product2',bil.Billed*fx.FXRate,0)),  " & _
        "Sum(IIf(prd.Market='Product3',bil.Billed*fx.FXRate,0)),  " & _
        "Sum(bil.Billed*fx.FXRate) " & _
        "FROM dbo.BILLABLE bil INNER JOIN dbo.SERVICE_FLAGS_ACTIVE sfa ON bil.ServiceAt_Acct = sfa.ServiceAt_Acct AND bil.FiscalPeriod = sfa.FiscalPeriod " & _
        "INNER JOIN dbo.DISTRICTS dist ON bil.strDistrict = dist.strDistrict " & _
        "INNER JOIN dbo.FX fx ON dist.Currency = fx.Currency INNER JOIN dbo.PRODUCT_CODES prd ON bil.Product_Code = prd.ProdID " & _
        "WHERE bil.FiscalPeriod > 201200 And bil.FiscalPeriod <= " & EndPeriod & " And fx.Year = 2013 " & _
        "GROUP BY dist.Location_Name, sfa.Promo_Code, sfa.NA_Description;"
    
         
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
         
    'Clear Prior Data
        Sheets("SGXSR019").Visible = True
        Sheets("SGXSR019").Select
        Range("K8:Q8").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.ClearContents
        Range("K8").Select
        Set Destination = [SGXSR019!K8]
    
         'Create RecordSet
        Set Rs = New ADODB.Recordset
        
        Rs.Open strSQL, MyConn, adOpenForwardOnly, adLockReadOnly, adCmdText
        
         'Write RecordSet to results area
        Rw = Destination.Row
        Col = Destination.Column
        c = Col
        Do Until Rs.EOF
            For Each MyField In Rs.Fields
                Cells(Rw, c) = MyField
                c = c + 1
            Next MyField
            Rs.MoveNext
            Rw = Rw + 1
            c = Col
        Loop
        
        Set Rs = Nothing
    
        Sheets("Automation").Select
        Range("A1").Select
        Application.ScreenUpdating = True
        MsgBox "PY Billable Data Imported - One more retrieve!", vbExclamation, "My Company Financial Planning and Analysis"
        Application.Calculation = xlCalculationAutomatic
    
    Exit_BillablePY:
        Exit Sub   '<----Breaks Here
        
    Err_BillablePY:
        Debug.Print Err.Number & " - " & Err.Description
        Resume Exit_BillablePY
    
    End Sub
    stumped, and thanks in advance
    Sportsguy

  2. #2
    Valued Forum Contributor Neil_'s Avatar
    Join Date
    04-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Office 365 Enterprise E3 2013 / 2016
    Posts
    479

    Re: VBA error during execution at Exit Sub

    try this thread

    http://stackoverflow.com/questions/2...as-been-halted

    Hit Ctrl Break yourself before the code halts, then hit continue.
    Frob first, tweak later

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1