A
AngeloUCF
I keep getting an error at the rsResults.open line of this code:Run-
time error '-2147467259 (80004005)' ODBC--call failed. From what I've
researched it's fairly common, but no single solution. I get different
messages changing the sql string around, so I was hoping it might be
within the statement and I'm not seeing it. I've already got 3 other
queries being written to other worksheets in the book, just hanging up
on this one. Anyone see something funny? I've put a msgbox(sql) line
in there before executing and it looks fine to me.
P.S. I'm not a programmer, so I'm sure it's not the neatest and most
efficient code.
Public Function sqlNoPayoff(BC1 As Integer, BC2 As Integer)
Dim sql As String, i As Integer
Dim ad As ADODB.Connection
Dim rsResults As ADODB.Recordset
i = 0
sql = ""
'------------------------------
'WRITE RECORDSET TO WORKBOOK
'------------------------------
' Initiate connection to database and start a new recordset
Set ad = CurrentProject.Connection
Set rsResults = New ADODB.Recordset
' SQL for ERM Balance Control account balances
sql = "SELECT BC_Accounts.OW_ACCOUNT,"
sql = sql & " PSADM_PS_CI_FT.BAL_CTL_GRP_ID,"
sql = sql & " PSADM_PS_CI_FT_GL.JOURNAL_ID,"
sql = sql & " PSADM_PS_CI_FT.CUR_AMT,"
sql = sql & " PSADM_PS_CI_FT.TOT_AMT,"
sql = sql & " PSADM_PS_CI_FT_GL.MONETARY_AMOUNT"
sql = sql & " FROM BC_Accounts,"
sql = sql & " PSADM_PS_CI_FT,"
sql = sql & " PSADM_PS_CI_FT_GL"
sql = sql & " WHERE PSADM_PS_CI_FT.FT_ID =
PSADM_PS_CI_FT_GL.FT_ID"
sql = sql & " AND BC_Accounts.DEPTID =
PSADM_PS_CI_FT_GL.DEPTID"
sql = sql & " AND BC_Accounts.OPERATING_UNIT =
PSADM_PS_CI_FT_GL.OPERATING_UNIT"
sql = sql & " AND BC_Accounts.ACCOUNT =
PSADM_PS_CI_FT_GL.ACCOUNT"
sql = sql & " AND PSADM_PS_CI_FT.BAL_CTL_GRP_ID Between " & BC1
& " And " & BC2
sql = sql & " AND PSADM_PS_CI_FT.TOT_AMT = 0"
sql = sql & " AND PSADM_PS_CI_FT.FREEZE_SW = 'Y'"
sql = sql & " AND PSADM_PS_CI_FT.REDUNDANT_SW = 'N';"
rsResults.Open sql, ad, , , adAsyncExecute
Do While rsResults.State = adStateExecuting
DoEvents
Loop
' Write column headers
'ActiveCell.Offset(i, 0).Value = rsResults("OW_ACCOUNT").Name
ActiveCell.Offset(i, 1).Value = rsResults("BAL_CTL_GRP_ID").Name
ActiveCell.Offset(i, 2).Value = rsResults("JOURNAL_ID").Name
ActiveCell.Offset(i, 3).Value = rsResults("CUR_AMT").Name
ActiveCell.Offset(i, 4).Value = rsResults("TOT_AMT").Name
ActiveCell.Offset(i, 5).Value = rsResults("MONETARY_AMOUNT").Name
i = i + 1
Do While Not rsResults.EOF
' Write query data
ActiveCell.Offset(i, 0).Value = rsResults("OW_ACCOUNT")
ActiveCell.Offset(i, 1).Value = rsResults("BAL_CTL_GRP_ID")
ActiveCell.Offset(i, 2).Value = rsResults("JOURNAL_ID")
ActiveCell.Offset(i, 2).Value = rsResults("CUR_AMT")
ActiveCell.Offset(i, 2).Value = rsResults("TOT_AMT")
ActiveCell.Offset(i, 2).Value = rsResults("MONETARY_AMOUNT")
rsResults.MoveNext
i = i + 1
Loop
rsResults.Close
Set rsResults = Nothing
Set ad = Nothing
End Function
time error '-2147467259 (80004005)' ODBC--call failed. From what I've
researched it's fairly common, but no single solution. I get different
messages changing the sql string around, so I was hoping it might be
within the statement and I'm not seeing it. I've already got 3 other
queries being written to other worksheets in the book, just hanging up
on this one. Anyone see something funny? I've put a msgbox(sql) line
in there before executing and it looks fine to me.
P.S. I'm not a programmer, so I'm sure it's not the neatest and most
efficient code.
Public Function sqlNoPayoff(BC1 As Integer, BC2 As Integer)
Dim sql As String, i As Integer
Dim ad As ADODB.Connection
Dim rsResults As ADODB.Recordset
i = 0
sql = ""
'------------------------------
'WRITE RECORDSET TO WORKBOOK
'------------------------------
' Initiate connection to database and start a new recordset
Set ad = CurrentProject.Connection
Set rsResults = New ADODB.Recordset
' SQL for ERM Balance Control account balances
sql = "SELECT BC_Accounts.OW_ACCOUNT,"
sql = sql & " PSADM_PS_CI_FT.BAL_CTL_GRP_ID,"
sql = sql & " PSADM_PS_CI_FT_GL.JOURNAL_ID,"
sql = sql & " PSADM_PS_CI_FT.CUR_AMT,"
sql = sql & " PSADM_PS_CI_FT.TOT_AMT,"
sql = sql & " PSADM_PS_CI_FT_GL.MONETARY_AMOUNT"
sql = sql & " FROM BC_Accounts,"
sql = sql & " PSADM_PS_CI_FT,"
sql = sql & " PSADM_PS_CI_FT_GL"
sql = sql & " WHERE PSADM_PS_CI_FT.FT_ID =
PSADM_PS_CI_FT_GL.FT_ID"
sql = sql & " AND BC_Accounts.DEPTID =
PSADM_PS_CI_FT_GL.DEPTID"
sql = sql & " AND BC_Accounts.OPERATING_UNIT =
PSADM_PS_CI_FT_GL.OPERATING_UNIT"
sql = sql & " AND BC_Accounts.ACCOUNT =
PSADM_PS_CI_FT_GL.ACCOUNT"
sql = sql & " AND PSADM_PS_CI_FT.BAL_CTL_GRP_ID Between " & BC1
& " And " & BC2
sql = sql & " AND PSADM_PS_CI_FT.TOT_AMT = 0"
sql = sql & " AND PSADM_PS_CI_FT.FREEZE_SW = 'Y'"
sql = sql & " AND PSADM_PS_CI_FT.REDUNDANT_SW = 'N';"
rsResults.Open sql, ad, , , adAsyncExecute
Do While rsResults.State = adStateExecuting
DoEvents
Loop
' Write column headers
'ActiveCell.Offset(i, 0).Value = rsResults("OW_ACCOUNT").Name
ActiveCell.Offset(i, 1).Value = rsResults("BAL_CTL_GRP_ID").Name
ActiveCell.Offset(i, 2).Value = rsResults("JOURNAL_ID").Name
ActiveCell.Offset(i, 3).Value = rsResults("CUR_AMT").Name
ActiveCell.Offset(i, 4).Value = rsResults("TOT_AMT").Name
ActiveCell.Offset(i, 5).Value = rsResults("MONETARY_AMOUNT").Name
i = i + 1
Do While Not rsResults.EOF
' Write query data
ActiveCell.Offset(i, 0).Value = rsResults("OW_ACCOUNT")
ActiveCell.Offset(i, 1).Value = rsResults("BAL_CTL_GRP_ID")
ActiveCell.Offset(i, 2).Value = rsResults("JOURNAL_ID")
ActiveCell.Offset(i, 2).Value = rsResults("CUR_AMT")
ActiveCell.Offset(i, 2).Value = rsResults("TOT_AMT")
ActiveCell.Offset(i, 2).Value = rsResults("MONETARY_AMOUNT")
rsResults.MoveNext
i = i + 1
Loop
rsResults.Close
Set rsResults = Nothing
Set ad = Nothing
End Function