Solved

Error 'BOF or EOF' in VB6

Posted on 2016-10-30
10
30 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

813 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