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
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
  • 6
  • 4
LVL 47

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 47

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.
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now


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.
LVL 47

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 47

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Use Windows Task Scheduler to print a Word document weekly so your printer ink won't dry out.
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

734 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