Jason0001
Programmer
- Aug 7, 2006
- 2
I am trying to perform an async call to an Oracle database. The code skips right through the execution of the statement (without running the sql), then hangs when I check to see if the recordset is at the end of file. The code is in Excel, but really could be in Access or even VBScript, for that matter. I have it set up to continue responding to system UI interactions while the sql is running, but the sql doesn't run until I do the "if rs.EOF" statement. Some of these statements take 2 hours to process, so I don't want to completely shut down Excel while this is happening. I'd rather at least have the ability to display the status bar to tell the user where the program is. Here's my code snippet: (Thanks!)
Dim cnCIS As New ADODB.Connection
Dim cmCIS As New ADODB.Command
Dim rs As New ADODB.Recordset
cnCIS.Open "#ODBC connection string#
cmCIS.ActiveConnection = cnCIS
Dim sql As String
sql = "#some sql statement#"
cmCIS.CommandText = sql
Set rs = cmCIS.Execute(, , adAsyncExecute)
Do While (cmCIS.State And adStateExecuting) = adStateExecuting
DoEvents
Loop
If Not rs.EOF Then Range("charges").Value = rs("amount")
'code hangs on the above statement
rs.Close
Application.StatusBar = "Charges complete"
DoEvents
Dim cnCIS As New ADODB.Connection
Dim cmCIS As New ADODB.Command
Dim rs As New ADODB.Recordset
cnCIS.Open "#ODBC connection string#
cmCIS.ActiveConnection = cnCIS
Dim sql As String
sql = "#some sql statement#"
cmCIS.CommandText = sql
Set rs = cmCIS.Execute(, , adAsyncExecute)
Do While (cmCIS.State And adStateExecuting) = adStateExecuting
DoEvents
Loop
If Not rs.EOF Then Range("charges").Value = rs("amount")
'code hangs on the above statement
rs.Close
Application.StatusBar = "Charges complete"
DoEvents