View Single Post
  #1 (permalink)  
Old October 7th, 2003, 05:41 AM
twsinc twsinc is offline
Authorized User
Join Date: Sep 2003
Location: Upper Marlboro, Maryland, USA.
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default Intelligent Navigation Buttons

I worked through many of the examples in the book, Beginning Access 2002 VBA. The VBA code for intelligent navigation buttons (Private Sub Form_Current( ) – page 241 & 242) worked for the Ice Cream Database; however, it did not work when I copied the code over to my database to navigate through a form that keeps track of personal information for my employees. When I attempt to open my form, I get a “Runtime Error ‘13’: Type Mismatch.” I would appreciate help from anyone familiar with this section of the book, or anyone else who may be able to give me some suggestions.

FYI, the code follows.



Private Sub Form_Current()
Dim recClone As Recordset

'Make a clone of the recordset underlying the form so
'we can move around that without affecting the form's
Set recClone = Me.RecordsetClone()

'If we are in a new record. disable the <Next> button
'and enable the rest of the buttons
If Me.NewRecord Then
    cmdFirst.Enabled = True
    cmdPrevious.Enabled = True
    cmdNext.Enabled = False
    cmdLast.Enabled = True
    cmdNew.Enabled = False
    Exit Sub
End If

'If we reach here, we know we are not in a new record
'so we can enable the <New> button if the form allows
'new records to be added
cmdNew.Enabled = Me.AllowAdditions

'But we need to check if there are no records. If so
'we disable all buttons except for the <New> button
If recClone.RecordCount = 0 Then
    cmdFirst.Enabled = False
    cmdNext.Enabled = False
    cmdPrevious.Enabled = False
    cmdLast.Enabled = False

    'If there are records, we know that the <First> and
    '<Last> button will always be enabled, irrespective
    'of where we are in the recordset

    cmdFirst.Enabled = True
    cmdLast.Enabled = True

    'Syncronize the currect pointer in the two recordsets

    recClone.Bookmark = Me.Bookmark

    'Next we must see if we are on the first record
    'If so, we should disable the <Previous> button

    cmdPrevious.Enabled = Not (recClone.BOF)

    'And then check whether we are on the last record
    'If so, we should disable the <Next> button

    cmdNext.Enabled = Not (recClone.EOF)
End If

'And finally close the cloned recordset


End Sub

Reply With Quote