Trouble with cmd button

  • Thread starter Afrosheen via AccessMonster.com
  • Start date
A

Afrosheen via AccessMonster.com

I have a form with cmdNext and cmdPrevious. and It works like it should. The
problem is that when the recordset is set the cmdNext button is enabled. What
I'd like it to do is disable it on the first record of the recordset. Can
this be done? This is the code I'm using now.

Private Sub Form_Current()
Dim rsClone As Recordset
10 Set rsClone = Me.RecordsetClone
20 If Me.NewRecord = True Then
30 Me!cmdNext.Enabled = False
40 Me!cmdPrevious.Enabled = True
50 ElseIf rsClone.Bookmarkable = True Then
60 rsClone.Bookmark = Me.Bookmark
70 rsClone.MovePrevious
80 cmdPrevious.Enabled = Not (rsClone.BOF)
90 rsClone.MoveNext
100 rsClone.MoveNext
140 cmdNext.Enabled = Not (rsClone.EOF)
160 rsClone.MovePrevious
170 End If
End Sub

Thanks for reading this post. I appreciate any help I can get.
 
F

fredg

I have a form with cmdNext and cmdPrevious. and It works like it should. The
problem is that when the recordset is set the cmdNext button is enabled. What
I'd like it to do is disable it on the first record of the recordset. Can
this be done? This is the code I'm using now.

Private Sub Form_Current()
Dim rsClone As Recordset
10 Set rsClone = Me.RecordsetClone
20 If Me.NewRecord = True Then
30 Me!cmdNext.Enabled = False
40 Me!cmdPrevious.Enabled = True
50 ElseIf rsClone.Bookmarkable = True Then
60 rsClone.Bookmark = Me.Bookmark
70 rsClone.MovePrevious
80 cmdPrevious.Enabled = Not (rsClone.BOF)
90 rsClone.MoveNext
100 rsClone.MoveNext
140 cmdNext.Enabled = Not (rsClone.EOF)
160 rsClone.MovePrevious
170 End If
End Sub

Thanks for reading this post. I appreciate any help I can get.

You can adapt this. Change the button names as needed.

Private Sub Form_Current()

CmdPreviousRecord.Enabled = Not Me.CurrentRecord = 1
CmdNextRecord.Enabled = Me.CurrentRecord = 1 Or Me.CurrentRecord <
Me.Recordset.RecordCount
End Sub
 
A

Afrosheen via AccessMonster.com

Thanks for your reply. I copied and pasted the lines of code in. The problem
is with line 2
CmdNextRecord.Enabled = Me.CurrentRecord = 1 Or Me.CurrentRecord <

Am I to guess that it was supposed to be <1?
Like I said I'm just guessing. I 'll give it a shot and get back to you.

I have a form with cmdNext and cmdPrevious. and It works like it should. The
problem is that when the recordset is set the cmdNext button is enabled. What
[quoted text clipped - 19 lines]
Thanks for reading this post. I appreciate any help I can get.

You can adapt this. Change the button names as needed.

Private Sub Form_Current()

CmdPreviousRecord.Enabled = Not Me.CurrentRecord = 1
CmdNextRecord.Enabled = Me.CurrentRecord = 1 Or Me.CurrentRecord <
Me.Recordset.RecordCount
End Sub
 
A

Afrosheen via AccessMonster.com

I found out what it was. I forgot that this screen word wraps. It's working
as you describe. What I would like and I don't know is if it can be done is:

When I enter the last name of a search and there's more than one record
that's when I want the cmdNext button enabled. So, If I start the program
both the cmdNext and cmdPrevious are NOT enabled.
Thanks for your help.
Thanks for your reply. I copied and pasted the lines of code in. The problem
is with line 2
CmdNextRecord.Enabled = Me.CurrentRecord = 1 Or Me.CurrentRecord <

Am I to guess that it was supposed to be <1?
Like I said I'm just guessing. I 'll give it a shot and get back to you.
[quoted text clipped - 10 lines]
Me.Recordset.RecordCount
End Sub
 

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

Top