Solved

Error 'BOF or EOF' in VB6

Posted on 2016-10-30
10
34 Views
Last Modified: 2016-11-04
We have an old VB6 apps that when run within the designer, works well, but when created the EXE or executable (files >> Make Code-Name), it gives the following error:

Run-time error '3021':
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

Please advice on what is happening

Thank you in advance.
0
Comment
Question by:rayluvs
  • 6
  • 4
10 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41865866
Please show the procedure where this error occurs.
0
 

Author Comment

by:rayluvs
ID: 41865896
It happens when the project executed when created in as exe file not in the developer design screen (when run to test); there all is ok.

However, based that the error happens when we press the button where the following routine is executed:


 cnn.Open "Provider=SQLOLEDB; " & _
          "Initial Catalog=" & lCompanyDB & "; " & _
          "Data Source=" & SqlServerName & "; " & _
          "integrated security=SSPI; persist security info=True;"
  
  Set rstVendor = New ADODB.Recordset
  sSql = "<query contents>"
  rstVendor.Open sSql, cnn, adOpenKeyset, adLockOptimistic
 
  Dim tableContent As String
  Dim columnDelim As String, rowDelim As String, nullValue As String
  columnDelim = ",": rowDelim = vbCrLf: nullValue = "NULL"
  tableContent = rstVendor.GetString(adClipString, , columnDelim, rowDelim, nullValue)

Open Vars2 For Output As #1
Print #1, tableContent
Close #1

Open in new window

0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41865911
When something goes wrong when running the exe but not while developing, it's usually caused by the fact the the exe runs faster and some external and/or slower processes don't complete on time before the actual code speeds on ahead. To slow it down a bit try putting  a DoEvenrs after line 8 and perhaps after line 15.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:rayluvs
ID: 41865921
Hi, Thanx!

Sorry about the info, it does happen in design and we found the problem:

If the query is empty in line 8, ' rstVendor.Open sSql, cnn, adOpenKeyset, adLockOptimistic', then the line '
tableContent = rstVendor.GetString(adClipString, , columnDelim, rowDelim, nullValue)
' displays the error.

How can we fix this?
0
 

Accepted Solution

by:
rayluvs earned 0 total points
ID: 41865943
Ok fixed it (we think).  We just added an EOF so it can detect NO-DATA results:

rstVendor.Open sSql, cnn, adOpenKeyset, adLockOptimistic
If rstVendor.EOF Then
   MsgBox "NO DATA IN RESULTS"
   Exit Sub
   End If

Open in new window



Is this sufficient?  Please advice.
0
 
LVL 46

Assisted Solution

by:Martin Liss
Martin Liss earned 500 total points
ID: 41865949
It should be.
0
 

Author Comment

by:rayluvs
ID: 41865953
Up to now, all is ok!

Thanx!
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41865965
You're welcome and thanks for selecting my answer.

If you expand the “Full Biography” section of my profile you'll find links to some articles I've written that may interest you.

Marty - Microsoft MVP 2009 to 2016
              Experts Exchange MVE 2015
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2015
0
 

Author Comment

by:rayluvs
ID: 41866090
Thanx!!! Sure, will do!!
0
 

Author Closing Comment

by:rayluvs
ID: 41873685
Selected our entry as Best since it fixed it.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Modern/Metro styled message box and input box that directly can replace MsgBox() and InputBox()in Microsoft Access 2013 and later. Also included is a preconfigured error box to be used in error handling.
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

830 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