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
Bookmarks