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

Why doesn't EOF work in VBA for Access 97

Status
Not open for further replies.

Stargazer78

Technical User
Mar 13, 2000
3
US
Can anyone help me with some code for Access 97. I have a form that goes through records in a table called &quot;people&quot;.<br>
For some reason the EOF or BOF won't work like it does in Visual Basic 5. I have a previous button and a next button on my form and for some reason I can't get those buttons to jump to the beginning of the file when necessary.<br>
<br>
Help me?!!?!?
 
Lets see some code...<br>
Not usre wny you are writting code when the Navigation buttons at the bototm of a form are already working.<br>
<br>
<p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
 
Private Sub cmdNext_Click()<br>
<br>
Dim db As Database<br>
Dim rst As Recordset<br>
<br>
Set db = CurrentDb<br>
Set rst = db.OpenRecordset(&quot;people&quot;)<br>
<br>
If rst.EOF Then<br>
rst.MoveFirst<br>
Else<br>
rst.MoveNext<br>
End If<br>
<br>
End Sub<br>
<br>
The error I get is &quot;Object variable or with block variable not set&quot;
 
The Error comes from the recordset being closed somewhere.<br>
Which line is the error stoping on? <p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
 
I didn't save the file before I tried running it again, I no longer get the error, but the button doesn't seem to do anything. It just stays with the current record.<br>
<br>
Same code as before, but no error pops up. It just doesn't do anything.
 
Stargazer,<br>
A couple of things...You should explicitely set the recordset type, ie. dbOpenSnapshot, etc. Eof and Bof and MoveFirst behave differently for different types. <br>
<br>
Is this table the source of the form? If so, you could use the docmd.gotorecord...etc., or you could use the recordsetclone, which is the way I prefer:<br>
<br>
Dim rst as recordset<br>
set rst = me.recordsetclone<br>
'(trap for eof error here, I'm omitting for clarity)<br>
rst.movenext<br>
me.bookmark = rst.bookmark<br>
end sub<br>
<br>
Incidentally, if you have ADO loaded as a reference as well as DAO, it can conflict with DAO, which I've seen cause either the behaviour you describe, or Type Mismatch when setting a recordest variable via a valid OpenRecordset method, and other seemingly bizzare errors.<br>
<br>
--Jim
 
I don't know about Access 97, but in Access 2000, the default ADO cursor type is adOpenForwardOnly according to an instruction CD I have.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top