?
Solved

Database recordset error

Posted on 2004-04-28
7
Medium Priority
?
782 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

649 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