D
Dylan Moran
Hi,
The following is code for my navigation buttons. When a subform loads,
depending on where in the recordset you are, the navigation buttons are
either enabled or disabled.
My problem being is that when a subform loads, and there are no records yet
in the subform, my code to disable the 'previous' command button (cmd_prev)
does not appear to be working. I would really appreciate someone looking at
my code and seeing if you can spot the error. I think there may be some sort
of logical conflict with the
If recClone.RecordCount = 0 Then
and the
If Me.NewRecord Then
parts of the code.
Thanks in advance.
'********Code Starts here*************
Private Sub Form_Current()
Dim recClone As Recordset
Dim intNewRecord As Integer
'Make a clone of the recordset underlying the form so
'we can move around that without affecting the form's
'recordset
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
Me.cmd_previous.Enabled = True
Me.cmd_next.Enabled = False
Me.cmd_new.Enabled = True
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
Me.cmd_new.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
Me.cmd_next.Enabled = False
Me.cmd_previous.Enabled = False
Else
'If there are records, we know that the <First> and
'<Last> buttons will always be enabled, irrespective
'of where we are in the recordset
'Synchronize the current pointer in the two recordsets,
' that is the form recordset and the cloned recordset
recClone.Bookmark = Me.Bookmark
'Next, we must see if we are on the first record
'If so, we should disable the <Previous> button
recClone.MovePrevious
Me.cmd_previous.Enabled = Not (recClone.BOF)
recClone.MoveNext
'And then check whether we are on the last record
'If so, we should disable the <Next> button
recClone.MoveNext
Me.cmd_next.Enabled = Not (recClone.EOF)
recClone.MovePrevious
End If
'And finally close the cloned recordset
recClone.Close
End Sub
' ************** Code Ends Here *************
The following is code for my navigation buttons. When a subform loads,
depending on where in the recordset you are, the navigation buttons are
either enabled or disabled.
My problem being is that when a subform loads, and there are no records yet
in the subform, my code to disable the 'previous' command button (cmd_prev)
does not appear to be working. I would really appreciate someone looking at
my code and seeing if you can spot the error. I think there may be some sort
of logical conflict with the
If recClone.RecordCount = 0 Then
and the
If Me.NewRecord Then
parts of the code.
Thanks in advance.
'********Code Starts here*************
Private Sub Form_Current()
Dim recClone As Recordset
Dim intNewRecord As Integer
'Make a clone of the recordset underlying the form so
'we can move around that without affecting the form's
'recordset
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
Me.cmd_previous.Enabled = True
Me.cmd_next.Enabled = False
Me.cmd_new.Enabled = True
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
Me.cmd_new.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
Me.cmd_next.Enabled = False
Me.cmd_previous.Enabled = False
Else
'If there are records, we know that the <First> and
'<Last> buttons will always be enabled, irrespective
'of where we are in the recordset
'Synchronize the current pointer in the two recordsets,
' that is the form recordset and the cloned recordset
recClone.Bookmark = Me.Bookmark
'Next, we must see if we are on the first record
'If so, we should disable the <Previous> button
recClone.MovePrevious
Me.cmd_previous.Enabled = Not (recClone.BOF)
recClone.MoveNext
'And then check whether we are on the last record
'If so, we should disable the <Next> button
recClone.MoveNext
Me.cmd_next.Enabled = Not (recClone.EOF)
recClone.MovePrevious
End If
'And finally close the cloned recordset
recClone.Close
End Sub
' ************** Code Ends Here *************