-
Thanks for the quick answer! The point of the code was to test, if one could run lots of small queries fast, that's why the infinite loop. There was a breakpoint in the loop so I could stop the execution when I wanted
I didn't test the speedup routines because the problem was solved on an other forum. I didn't close myRecordset before trying to assign a new one to the same variable and it somehow caused a slowdown. I added the modified code below, thanks for your time!
Link to the other thread: bit.ly/N4KTS1
[VBA]Sub Macro1()
Dim myRecordset As Recordset
Dim myConn As Connection
Dim myCmd As Command
sqlCommand = "SELECT CategoryId, CategoryName FROM H_BudgetEntries WHERE CategoryId=1 Or CategoryId=2"
Set myConn = New Connection
With myConn
.ConnectionString = "Provider=SQLOLEDB;Initial Catalog=TESTDB;Data Source=.;Trusted_connection=yes;"
.Open
End With
Set myCmd = New Command
myCmd.CommandText = sqlCommand
Set myCmd.ActiveConnection = myConn
Range("A5").Select
Do While True ' Infinite loop
Set myRecordset = myCmd.Execute ' This line of code takes almost 10 seconds to complete, but only on every other time it is run
Selection.Value = myRecordset.Fields(1)
Selection.Offset(1, 0).Select 'BREAKPOINT HERE
myRecordset.Close
Set myRecordset = Nothing
Loop
End Sub [/VBA]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules