My problem is that i'm doing the check algorithm when the click event is pressed (set all buttons false, if EOF is false, enabled last and next buttons, if BOF is false, enable first and previous buttons. However, when i test it and click next until it reaches the last record, i have to click it one more time for it to be disabled:
rs a recordset object
Private Function checkRecord() As Boolean
checkRecord = True
tsbLast.Enabled = False
tsbNext.Enabled = False
tsbFirst.Enabled = False
tsbPrevious.Enabled = False
If Not rs.EOF Then
rs.MoveNext()
If Not rs.EOF Then
tsbLast.Enabled = True
tsbNext.Enabled = True
Else
checkRecord = False
End If
rs.MovePrevious()
End If
If Not rs.BOF Then
rs.MovePrevious()
If rs.BOF Then
checkRecord = False
Else
tsbFirst.Enabled = True
tsbPrevious.Enabled = True
End If
rs.MoveNext()
End If
End Function
Is there a cursor location property that returns a integer identifying location of the record? I really hate how BOF and EOF returns true only if the current cursor location is after the last or before the first (its like starting an index at -1, and not 0, and i can't add or subtract from the EOF and BOF indices) or a much more efficient way of doing this?
You might want to look into using the recordset object's AbsolutePosition property. Combined with the Recordcount property, you should be able to determine your current location at all times. Note this depends on the underlying OLEDB provider you are using. For more information please visit http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdproabpos.asp
Regards, Uwa.
|||Hello,
What I've done in the past with ado to get around this is to create a member variable, called say "_CurrentPosition" that I set to 0 when I first populate the RS, then increment/decrement when MoveN is called. This way, you can just check the _CurrentPosition variable to achieve what you want:
if (CurrentPosition == rs.RecordCount)
{
// disable move next button etc
}
else if (CurrentPosition = 0) //or 1 if you didn't create it as zero-based!
{
// disable move first button etc
}
I know it's not exactly what you're after, but there is no native property/method that ado exposes. As you may have discovered, the EndOfRecordset event fires only after you attempt to move beyong EOF...
Cheers,
Rob
|||Hello,
Just seconding what Uwa said: be careful using the AbsolutePosition property as this is provider dependent and I have never been able to utilise it with any degree of confidence.
Cheers,
Rob
|||You can try using ADO Data Control. You can find an example at - http://www.devarticles.com/c/a/Visual-Basic/Implementing-An-ADO-Data-Control-With-VB6/|||Thanks for all the replies, it seems that using OleDB as the provider instead of ADODB would make the most sense. It is a bit more coding, but not enough to persuade me to mess with ADO
No comments:
Post a Comment