Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run Time Error with ADO, VB6

Status
Not open for further replies.

Rob7

Programmer
Dec 12, 2001
152
US
Hi,
I am currently working on a project and found that when I executed a sql statement for a recordset, and that recordset returned no value (no records met the coditions of the sql statement), I get a Run Time Error 3021 with the explaination that "Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record." I have been to Microsoft's website and a search of the knowledgebase turned up this very error but in he context of a PIP Administrator.

Is this what is supposed to be returned from ADO or did I miss some sort of patch to VB6 that would have fixed this?
 
After the statement what kind of operation youre doing?

Try checking the recordcount of the ado recordset after the sql
statement so if the recordcount is above 0 then you do something
else do nothing.

i think even the movefirst procedure causes error if there is no record.
 
I suspect you do have a few record stored in the database and that you know your SQL statement.

Well, Have you tried using (eg: data1.recordsource = "SELECT * FROM tablename WHERE FirstName ='Joe'"

Where tablename = the name of the table you're searching from, and assuming you have a field called FirstName.

Try this in design mode first and if it works, then try the exact same thing in RUN Mode.

Hope I helped,

Andy.
 
I am setting the recordset index equal to a variable:

strMyString = rstMyRecSet(0)

I am thwarting the error by saying:

If rstMyRecSet.EOF and rstMyRecSet.BOF Then
Do Something
End If

I just wondered if this was the way it is supposed to work.
 
Note that RecordCount only works with a limited number of Cursor types - for general use .EOF and .BOF
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
if that are both equal at Form_load, the you need to add this:

Sub Form_Load()
If rstMyRecSet.EOF and rstMyRecSet.BOF Then
rstMyRecSet.AddNew
Else
rstMyRecSet.MoveFirst
CurrRec=1

rstMyRecSet.MoveLast
TotRec=rstMyRecSet.Recordcount

If CurrRec=TotRec then
MsgBox"Somethings Wrong!!",vbInformation,"Help"
End
End IF
End If
End Sub
 
The conditions that could exist with the sql statement are 1)there is not a record in which case I write a record with an INSERT statement
2)there is a record and I use an UPDATE statement

I guess this is just the way ADO returns an empty condition. At any rate, the test for RecSet.EOF and RecSet.BOF seems to be working.

Thanks all

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top