Inactivate command button when no records

  • Thread starter Thread starter magmike
  • Start date Start date
M

magmike

I have a subform that shows multiple records (notes) per client. In
the subform header are navigation buttons including a button to create
a new record. I have successfully programmed the buttons to disable
when there is no more records in their direction this way (please tell
me if there is a better way):

If Me.RecordsetClone.RecordCount - Me.CurrentRecord = 0 Then
Me.GoNext.Enabled = False
Me.GoLast.Enabled = False
Else:
Me.GoNext.Enabled = True
Me.GoLast.Enabled = True
End If

If Me.CurrentRecord = 1 Then
Me.GoPrevious.Enabled = False
Me.GoFirst.Enabled = False
Else:
Me.GoPrevious.Enabled = True
Me.GoFirst.Enabled = True
End If

However, I am trying to disable all these buttons (except the New
Record button) when there are no records on the form. I haven't
figured that one out yet. This is what I tried (unsuccessfully):

If IsNull(Me.Recordset) Then
Me.GoPrevious.Enabled = False
Me.GoFirst.Enabled = False
Me.GoNext.Enabled = False
Me.GoLast.Enabled = False
Else:
Me.GoPrevious.Enabled = True
Me.GoFirst.Enabled = True
Me.GoNext.Enabled = True
Me.GoLast.Enabled = True
End If

Thanks in advance for your help!

magmike
 
Try this (I have added line continuation characters to the code to
adjust for the newsgroup line wrap);

Private Sub Form_Current()

With Me
.GoFirst.Enabled = .RecordsetClone.RecordCount > 0 And _
.CurrentRecord <> 1
.GoPrevious.Enabled = .RecordsetClone.RecordCount > 0 And _
.CurrentRecord <> 1
.GoNext.Enabled = .RecordsetClone.RecordCount > 0 And _
.CurrentRecord <> .RecordsetClone.RecordCount
.GoLast.Enabled = .RecordsetClone.RecordCount > 0 And _
.CurrentRecord <> .RecordsetClone.RecordCount
End With

End Sub
 
Try this (I have added line continuation characters to the code to
adjust for the newsgroup line wrap);

Private Sub Form_Current()

With Me
    .GoFirst.Enabled = .RecordsetClone.RecordCount > 0 And _
                               .CurrentRecord <> 1
    .GoPrevious.Enabled = .RecordsetClone.RecordCount > 0 And _
                                     .CurrentRecord <> 1
    .GoNext.Enabled = .RecordsetClone.RecordCount > 0 And _
                               .CurrentRecord <> .RecordsetClone.RecordCount
    .GoLast.Enabled = .RecordsetClone.RecordCount > 0 And _
                               .CurrentRecord <> .RecordsetClone.RecordCount
End With

End Sub
--
_________

Sean Bailey











- Show quoted text -

That's a nice short cut for the first part, thanks!
 
It will also resolve the second part of your code as well. If there are
no records, the buttons will be disabled.
 
Try this (I have added line continuation characters to the code to
adjust for the newsgroup line wrap);

Private Sub Form_Current()

With Me
.GoFirst.Enabled = .RecordsetClone.RecordCount > 0 And _
.CurrentRecord <> 1
.GoPrevious.Enabled = .RecordsetClone.RecordCount > 0 And _
.CurrentRecord <> 1
.GoNext.Enabled = .RecordsetClone.RecordCount > 0 And _
.CurrentRecord <> .RecordsetClone.RecordCount
.GoLast.Enabled = .RecordsetClone.RecordCount > 0 And _
.CurrentRecord <> .RecordsetClone.RecordCount
End With

End Sub
--
_________

Sean Bailey











- Show quoted text -

That's a nice short cut for the first part, thanks!
 
Try this (I have added line continuation characters to the code to
adjust for the newsgroup line wrap);

Private Sub Form_Current()

With Me
.GoFirst.Enabled = .RecordsetClone.RecordCount > 0 And _
.CurrentRecord <> 1
.GoPrevious.Enabled = .RecordsetClone.RecordCount > 0 And _
.CurrentRecord <> 1
.GoNext.Enabled = .RecordsetClone.RecordCount > 0 And _
.CurrentRecord <> .RecordsetClone.RecordCount
.GoLast.Enabled = .RecordsetClone.RecordCount > 0 And _
.CurrentRecord <> .RecordsetClone.RecordCount
End With

End Sub
--
_________

Sean Bailey











- Show quoted text -

That's a nice short cut for the first part, thanks!
 
Try this (I have added line continuation characters to the code to
adjust for the newsgroup line wrap);

Private Sub Form_Current()

With Me
.GoFirst.Enabled = .RecordsetClone.RecordCount > 0 And _
.CurrentRecord <> 1
.GoPrevious.Enabled = .RecordsetClone.RecordCount > 0 And _
.CurrentRecord <> 1
.GoNext.Enabled = .RecordsetClone.RecordCount > 0 And _
.CurrentRecord <> .RecordsetClone.RecordCount
.GoLast.Enabled = .RecordsetClone.RecordCount > 0 And _
.CurrentRecord <> .RecordsetClone.RecordCount
End With

End Sub
--
_________

Sean Bailey











- Show quoted text -

That's a nice short cut for the first part, thanks!
 
Back
Top