Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to read a recordset file in VB6?

Posted on 2001-08-08
7
Medium Priority
?
844 Views
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
  mrsRun.Close
End Sub

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

Author Comment

by:daquin
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?  
0
 
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.
0
Independent Software Vendors: 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

by:daquin
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?
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 300 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
to
mrsRun.Save msFileName, adPersistXML
0
 
LVL 4

Expert Comment

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

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

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.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…
Suggested Courses

618 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