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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BOF and EOF

Status
Not open for further replies.

JTan

Technical User
Oct 9, 2001
73
SG
hi,

this may seem like a stupid question, but I do hope that someone will give me a reply. What is actually BOF and EOF? I know they stand for beginning of file and end of file respectively. I am just wondering when it says beginning of file, it is pointing to the first location of the file and therefore, infers that a record exists rite?

Yet when I was running my program, I keep getting this error saying that a current record is required. (BOF and EOF cannot be true ==> why?).I am wondering if I get my syntax wrong.

If Adodc1.Recordset.BOF = True Then

With Adodc1.Recordset

!due_date = MSFlexGrid1.TextMatrix(i, 3)
!transaction_status = "N"
.Update

End With

txtdisplay = "Successful Update!"
Else
txtdisplay = "Renewal quota is reached or the book is not borrowed!"
End If
 
hie,
You need to understand BOF and EOF markers correctly. What you have percieved to date is not right.
Every recordset needs to know where the first and the last record exists in a recordset in order to work. This problem is solved by using BOF and EOF markers which do nothng but act as hearders of a file which points to the start and end of file.
here is a pattern of a recordset


BOF 1 2 3 4 5 ............... 24 25 EOF

where BOF is the Begining of file header
EOF is the End of file header
and 1 to 25 are the record numbers


IF you are at BOF it means you are not at the First recod to start working with first record you have to move to it using MoveFirst method of recordset object.

similarly, EOF informs you that there is no more records left at the end of a file and you have reached End of File.


Remember

BOF = True means you have reached begin of file
Eof = True means you have reached end of file
also BOF = True and EOF = True means there are no records
in a recordset therefore
recordset is empty.


The code should look like this :



Adodc1.Recordset.MoveFirst
If NOT Adodc1.Recordset.EOF = True Then

With Adodc1.Recordset

!due_date = MSFlexGrid1.TextMatrix(i, 3)
!transaction_status = "N"
.Update

End With

txtdisplay = "Successful Update!"
Else
txtdisplay = "Renewal quota is reached or the book is not borrowed!"
End If







I hope this helps !!! [love]

BYe
miq







 
The usual method for going through the records in a recordset uses something like this:

Code:
Dim cn as ADODB.Connection
Dim rst as ADODB.Recordset
Dim MySQL as String
Dim a as Integer
With cn
.ConnectionTimeout =25        
.Provider= "sqloledb"
.Properties("Data Source").Value =ServerName     
.Properties("Initial Catalog").Value = DBName    
.Properties("User ID").Value = UserName
.Properties("Password").Value = Password
.Open
End With
MySQL = "SELECT * FROM tblWhatever"
Set rst = New Recordset
With rst
    Set rst.ActiveConnection = cn
    .CursorType = adOpenKeyset
    .LockType = adLockOptimistic
    .Open mySQL
    Do While Not rst.EOF
   'Your code for this record goes here
   .MoveNext
   Loop
    rst.Close
    Set rst = Nothing
 End With
cn.Close
set cn = Nothing
This is for a SQL database, you'll have to use whatever connection string your database needs.

Hope this helps
 
thanks for the replies!!

miq>> I tried ur way...but I am still getting errors. The problem now is "Either BOF or EOF is true, or the current record is deleted. Requested operation needs a current record."

code is as follows now:

Adodc1.RecordSource = "Select * from Transactionheader where book_no = '" & txtISBN1.Text & "' and transaction_status = 'B'"
Adodc1.Refresh

Adodc1.Recordset.MoveFirst
If Not Adodc1.Recordset.EOF = True Then

With Adodc1.Recordset

!due_date = MSFlexGrid1.TextMatrix(i, 3)
!transaction_status = "N"
.Update

End With

txtdisplay = "Successful Update!"
Else
txtdisplay = "Renewal quota is reached or the book is not borrowed!"
End If

 
You can't use the MoveFirst Method if the recordset is empty either. The only way I know of to ensure you perform operations on a non-empty recordset is to evaluate the BOF and EOF together. If BOF and EOF are both true then there are no records:

If Not (rs.BOF and rs.EOF) then
'the recordset is not empty
rs.MoveFirst ' etc...
else
'the recordset is empty
end if

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top