How to read a recordset file in VB6?

Posted on 2001-08-08
Last Modified: 2008-03-03
I am using VB6 and having trouble reading a recordset file created from an Access 97 database. The ExportData code below creates a file of what appears to be appropriate size. However, when I try to read the file in UpdateDB, the second line (rsInput.MoveFirst) generates error 3021, Either BOF or EOF is true.  The size of the file indicates that records are there. I have used similar code in other programs successfully. What is wrong here?

Dim msFileName as String            '-- name of quarterly export/import file
Dim mrsRun As New ADODB.Recordset   '-- recordset for used to create file
Dim mrsInput As New ADODB.Recordset  '-- recordset for to read data from file

Private Sub ExportData()
'-- export data to a recordset file
  '-- assign file name  
  msFileName = "QData" & ".rs" '-- let extension show file type  
  '-- dump the data to a recordset
  sSQL = "Select * from tblRun;"  
  Set mrsRun = New ADODB.Recordset
  mrsRun.CursorType = adOpenDynamic
  mrsRun.LockType = adLockOptimistic
  mrsRun.CursorLocation = adUseClient
  mrsRun.Open sSQL, gdbConnection  
  '-- save recordset as a file
  mrsRun.Save msFileName
End Sub

Sub UpdateDB()      
  '-- open input file
  rsInput.Open msFileName, , , , adCmdFile     'This is the file created from tblRun
  rsInput.MoveFirst    <==== CRASHES HERE
End Sub
Question by:daquin
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
LVL 70

Expert Comment

by:Éric Moreau
ID: 6365623
The recordset is empty.

You can do something like:
if rsimput.recordcount>0 then rsinput.movefirst

Also, to open the file, use this shorter syntax:
rsInput.Open msFileName

Author Comment

ID: 6365701
I tried dumping data from different tables and got file sizes ranging from 2K to 40K. This make me believe the data is there, so why is the recordset empty?  
LVL 70

Expert Comment

by:Éric Moreau
ID: 6365748
Maybe it is just the header that is saved! Open the file into notepad. You will see some scarbled data but other will be readable.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 6365826
About 6 characters are displayed when I view the file in Notepad.  I looked at some files generated in the same mannner by another program.  These file can be read by yet another program.  They look similar in notepad to the file generated in this program.  File size does not seem to affect the number of character displayed. I renamed one the files known to be readable and tried to read it with this program - got the same error message.  I am using the Microsoft ActiveX Data Objects Recordset 2.5 Library.  Am I missing something here?
LVL 75

Accepted Solution

Anthony Perkins earned 100 total points
ID: 6365961
I don't believe this is the issue, but one thing I notice is that the line

Dim mrsRun As New ADODB.Recordset  
should be
Dim mrsRun As ADODB.Recordset  

Since you are instantiating the recordset in code with:
Set mrsRun = New ADODB.Recordset

A suggestion that would help deterine the problem is to save the recordset with XML and then you will be able to determine for sure whether there is data or not.

Just change the line
mrsRun.Save msFileName
mrsRun.Save msFileName, adPersistXML

Expert Comment

ID: 6366653
my practice, you need change code
    rsInput.Open msFileName, , , , adCmdFile
    rsInput.Open msFileName

BTW: in ExportData()
    '-- save recordset as a file
    Kill msFileName
    mrsRun.Save msFileName
if the file exited, save method will raise some error.

Expert Comment

by:Valliappan AN
ID: 6366808
You could check for recordcount like : (adding to emoreau's comments)

If rsInput.RecordCount <> 0 Then rsInput.MoveFirst

Since, sometimes, the RecordCount will be -1.

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…

742 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