EOF error syntax

  • Thread starter Cipher via AccessMonster.com
  • Start date
C

Cipher via AccessMonster.com

Is the following, the best way to detect an EOF condition?
Boolean_State=True
Do While Boolean_State
Set rs = New ADODB.Recordset
StrOne = "SELECT * FROM Inject_Cycle " & "WHERE ID=" & Record_Number
rs.Open StrOne, CurrentProject.Connection, adOpenForwardOnly,
adLockReadOnly
If rs.EOF Then
Boolean_State=False
GoTo End
End If
 
E

Edward

I use both .EOF and .BOF checks in virtually every recordset I open through
code in order to handle exceptions of when either is found. They work very
well for me, and it seems to be the easiest way to trap for the last record.

Regards

Edward
 
D

Dirk Goldgar

Cipher via AccessMonster.com said:
Is the following, the best way to detect an EOF condition?
Boolean_State=True
Do While Boolean_State
Set rs = New ADODB.Recordset
StrOne = "SELECT * FROM Inject_Cycle " & "WHERE ID=" &
Record_Number
rs.Open StrOne, CurrentProject.Connection, adOpenForwardOnly,
adLockReadOnly
If rs.EOF Then
Boolean_State=False
GoTo End
End If


What are you actually trying to do? If you just want to know if the
recordset you just opened is empty, all you have to do is check either its
EOF property or its BOF property, as both will be True. You don't need to
check both properties if you just opened the recordset yourself. If you
were passed a recordset in unknown state, not necessarily freshly opened,
then you should check both properties ("If rs.EOF And rs.BOF Then") to
verify that it's an emtpty recordset.

EOF is a boolean property, so I don't know why your example goes to the
trouble of defining and setting a boolean variable, unless there are other
conditions that may set that variable. But then, I don't know whether you
really want to be creating and opening the recordset inside the loop,
either. If your loop is just supposed to be looping through all the records
in the recordset, you ought to be opening the recordset outside the loop.
But if this recordset is just one of several you'll be processing inside
your loop, then maybe that's right. You really haven't given us enough
information about your intentions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top