Solved

Database recordset error

Posted on 2004-04-28
7
778 Views
Last Modified: 2013-11-26
Below is a function I am using to populate two Data controls recordset.
-----------------------------------------------------
Private Function populateCombos()

Dim sql1 As String
Dim sql2 As String

On Error GoTo ErrorHandler

    sql1 = "execute proc1"
    sql2 = "execute proc2"
   
    If ConnectToDB Then
        Set dat1.Recordset = dbMain.OpenRecordset(sql1, dbOpenDynaset, dbSQLPassThrough)
        Set dat2.Recordset = dbMain.OpenRecordset(sql2, dbOpenDynaset, dbSQLPassThrough)
        populateCombos = True
    Else
        msgbox "connection to database failed"
        populateCombos = False
    End If
   
    Exit Function

ErrorHandler:
    populateCombos = False

End Function
-------------------------------------------------

However, the second recordset open fails. The error msg says that the "Connection is busy with results for another htsmt"

I found somewhere that says this is due to the first recordset is still being worked on. However, I used this format of code before without problems. The difference this time is that I have not linked a grid to the Data Control.

I want to avoid opening multiple connections as I do not require ability to write.

Many thanks
0
Comment
Question by:2000bug
7 Comments
 
LVL 9

Expert Comment

by:p_sie
ID: 10937858
MAybe place a doEvents between the to database-calls?

 Set dat1.Recordset = dbMain.OpenRecordset(sql1, dbOpenDynaset, dbSQLPassThrough)
 DoEvents
 Set dat2.Recordset = dbMain.OpenRecordset(sql2, dbOpenDynaset, dbSQLPassThrough)
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 10937878
You may want to check the state bvefore


ie

dbMain.state


Constant Description
adStateClosed       Default. Indicates that the object is closed.
adStateOpen          Indicates that the object is open.
adStateConnecting Indicates that the Recordset object is connecting.
adStateExecuting    Indicates that the Recordset object is executing a command.
adStateFetching      Indicates that the rows of the Recordset object are being fetched.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10937974
to clarify what EDDYKT suggested, change your code like this (from this:

    If ConnectToDB Then
        Set dat1.Recordset = dbMain.OpenRecordset(sql1, dbOpenDynaset, dbSQLPassThrough)
        Set dat2.Recordset = dbMain.OpenRecordset(sql2, dbOpenDynaset, dbSQLPassThrough)
        populateCombos = True
    Else
        msgbox "connection to database failed"
        populateCombos = False
    End If

to:

    If ConnectToDB Then
        Set dat1.Recordset = dbMain.OpenRecordset(sql1, dbOpenDynaset, dbSQLPassThrough)

        ' wait until the first recordset is filled, before proceeding to second recordset
        Do While dbMain.State = adStateFetching
            DoEvents
        Loop

        Set dat2.Recordset = dbMain.OpenRecordset(sql2, dbOpenDynaset, dbSQLPassThrough)

        ' wait until the sedond recordset is filled, before proceeding
        Do While dbMain.State = adStateFetching
            DoEvents
        Loop

        populateCombos = True
    Else
        msgbox "connection to database failed"
        populateCombos = False
    End If

the second 'wait loop' is possible un-necessary, but it is better to be safe than sorry.

AW
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:2000bug
ID: 10938000
theres no dbMain.state

dbMain is a Database object
0
 

Author Comment

by:2000bug
ID: 10938199
I have resolved the issue.

The data was not 'flushed' out of the recordset. That is why it worked when I had a grid attached to the Data Control as it did that for me.

I simply had to do a MoveFirst MoveLast manually.

Thanks for your comments.

I shall request for a delete.
0
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 10971798
Closed, 250 points refunded.
PashaMod
Community Support Moderator
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now