Error 'BOF or EOF' in VB6

Posted on 2016-10-30
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.
Question by:rayluvs
  • 6
  • 4
LVL 45

Expert Comment

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

Author Comment

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

LVL 45

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.

Author Comment

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?

Accepted Solution

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
   Exit Sub
   End If

Open in new window

Is this sufficient?  Please advice.
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

LVL 45

Assisted Solution

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

Author Comment

ID: 41865953
Up to now, all is ok!

LVL 45

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

Author Comment

ID: 41866090
Thanx!!! Sure, will do!!

Author Closing Comment

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 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…
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…

758 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

19 Experts available now in Live!

Get 1:1 Help Now