Solved

Error 'BOF or EOF' in VB6

Posted on 2016-10-30
10
28 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel VBA problem Error 1004 2 41
Microsoft Word VBA navigate to tag property in same table row 1 19
ifna and iferror 1 32
vbModal 12 31
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
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…

932 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

14 Experts available now in Live!

Get 1:1 Help Now