Recordsets

  • Thread starter Thread starter Lathwella
  • Start date Start date
L

Lathwella

Guest
Help. This simple construction below should show the result of 2 as there are 2 records resulting form the query the recordset is set to. Why doesn't this work. I am always having trouble with recordsets they never function correctly and I seem never to be able to use them to navigate through records.
Here is my construct:-
Dim eventdb As Database
Dim eventrec As Recordset
Dim eventcount As Integer

Set eventdb = CurrentDb()
Set eventrec = eventdb.OpenRecordset("Pending Bookings query", dbOpenDynaset)
eventrec.MoveFirst
eventcount = eventrec.RecordCount

MsgBox eventcount
 
If you are using Access 97 this should work for you:

Private Sub Command0_Click()
Dim eventdb As Database
Dim eventrec As Recordset
Dim eventcount As Integer

Set eventdb = CurrentDb()

Set eventrec = eventdb.OpenRecordset("Pending Bookings query", dbOpenDynaset)
Do Until eventrec.EOF
eventrec.MoveNext

eventcount = eventrec.RecordCount
Loop
MsgBox eventcount
End Sub

If it is 2000 you may have to make some minor modifications. Let me know if you get an error and what error it is.
 
Ok if it is Access 2000 all you have to do is reference that the recordset is DAO to make it work.

Make this change to your declaration:

Dim eventrec As DAO.Recordset

By the way the reason you were only getting the 1 with your code was because without the loop Access only accesses the recordset once. The Do Until EOF (END OF FILE) works with the loop and will continue counting records until the end of the record set is reached.

[This message has been edited by Talismanic (edited 05-30-2001).]
 
Try this
Dim eventdb As Database
Dim eventrec As Recordset
Dim eventcount As Integer

Set eventdb = CurrentDb()
Set eventrec = eventdb.OpenRecordset("Pending Bookings query", dbOpenDynaset)
eventrec.MoveLast
eventcount = eventrec.RecordCount

MsgBox eventcount
 

Users who are viewing this thread

Back
Top Bottom