Solved

How to read a recordset file in VB6?

Posted on 2001-08-08
7
816 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
7 Comments
 
LVL 69

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 69

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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 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
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 run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

744 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

15 Experts available now in Live!

Get 1:1 Help Now