Inactivate command button when no records

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
 
B

Beetle

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
 
M

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
--
_________

Sean Bailey











- Show quoted text -

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

Beetle

It will also resolve the second part of your code as well. If there are
no records, the buttons will be disabled.
 
S

shirley hall

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!
 
S

shirley hall

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!
 
S

shirley hall

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Object Variable Error 7
Command Button Enable/Disable 3
Problem with Toggle Button. 10
Locking a record via a form 2
Controlling Edits 2
On Current 5
Radio Buttons Programming 5
First / Last nav button disable 1

Top