A
alex
Object Variable Error
Hello,
Using Access ’03…
On my Form, I have a label and command buttons that function like the
typical navigation buttons at the bottom of a form (mine are at the
top and a little more user-friendly).
There’s an issue with the code, however; which usually works rather
well.
When the form experiences a run-time error of any kind, I get a run-
time error (91) where I set Records.Bookmark = Me.Bookmark.
I’m guessing that once an error occurs, my recordset is being
dropped. All I have to do is open the form and everything works just
fine. Do I need to set a reference to a DAO database?
Here’s some of the code:
Option Compare Database
Option Explicit
Dim Records As DAO.Recordset
Dim TotalRecords
Private Sub Form_Load() 'used to count records
On Error Resume Next 'records.movelast will throw error if no records
exist
Set Records = Me.RecordsetClone
Records.MoveLast
TotalRecords = Records.RecordCount
End Sub
Private Sub Form_Current()
'code navigation buttons
If Not Me.NewRecord Then 'is not a new record
Records.Bookmark = Me.Bookmark ‘error occurs here after any run-
time error
Me![RecNum].Caption = "Record " & Records.AbsolutePosition + 1 & "
of " & TotalRecords
Me.cmdNextRecord.Enabled = True 'enable next record arrow
'Debug.Print Records.AbsolutePosition
If Records.AbsolutePosition = 0 Then 'first record
Me.cmdPreviousRecord.Enabled = False 'disable previous record
arrow
Else
Me.cmdPreviousRecord.Enabled = True 'enable previous record
arrow
End If
Else
Me![RecNum].Caption = "New Record"
Me.cmdNextRecord.Enabled = False 'disable next record arrow
Me.cmdPreviousRecord.Enabled = True 'enable previous record arrow
End If
End Sub
Thanks for the help,
alex
Hello,
Using Access ’03…
On my Form, I have a label and command buttons that function like the
typical navigation buttons at the bottom of a form (mine are at the
top and a little more user-friendly).
There’s an issue with the code, however; which usually works rather
well.
When the form experiences a run-time error of any kind, I get a run-
time error (91) where I set Records.Bookmark = Me.Bookmark.
I’m guessing that once an error occurs, my recordset is being
dropped. All I have to do is open the form and everything works just
fine. Do I need to set a reference to a DAO database?
Here’s some of the code:
Option Compare Database
Option Explicit
Dim Records As DAO.Recordset
Dim TotalRecords
Private Sub Form_Load() 'used to count records
On Error Resume Next 'records.movelast will throw error if no records
exist
Set Records = Me.RecordsetClone
Records.MoveLast
TotalRecords = Records.RecordCount
End Sub
Private Sub Form_Current()
'code navigation buttons
If Not Me.NewRecord Then 'is not a new record
Records.Bookmark = Me.Bookmark ‘error occurs here after any run-
time error
Me![RecNum].Caption = "Record " & Records.AbsolutePosition + 1 & "
of " & TotalRecords
Me.cmdNextRecord.Enabled = True 'enable next record arrow
'Debug.Print Records.AbsolutePosition
If Records.AbsolutePosition = 0 Then 'first record
Me.cmdPreviousRecord.Enabled = False 'disable previous record
arrow
Else
Me.cmdPreviousRecord.Enabled = True 'enable previous record
arrow
End If
Else
Me![RecNum].Caption = "New Record"
Me.cmdNextRecord.Enabled = False 'disable next record arrow
Me.cmdPreviousRecord.Enabled = True 'enable previous record arrow
End If
End Sub
Thanks for the help,
alex