Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want Next record button to grey out if no other records available 1

Status
Not open for further replies.

Cpreston

MIS
Mar 4, 2015
972
GB
Hi

I have used the wizard button to create a button for Next and previous record.

What I want is when the last record with any data is reached that it greys out and does not allow to go to next empty record.
I am using access 2010.

Any ideas please

Thanks
 
I also tried to this code but it only works with one record in the table.
If more than one it does not to go to the next record until the last one?

Private Sub nextrec_Click()
Dim rst As Recordset
Set rst = Forms!mainform.RecordsetClone
If Forms!mainform.CurrentRecord = rst.RecordCount Then
Forms!mainform.nextrec.Enabled = False
Else
Forms!mainform.nextrec.Enabled = True
End If
Set rst = Nothing
End Sub
 
Under data tab there is not an option to allow additions
 
Here's the code I use for custom navigation buttons; you can change the messages displayed to whatever you like:

Code:
Private Sub Go2Prev_Click()


  If Me.CurrentRecord = 1 Then

    MsgBox "You are on the First Record!"

  Else
  
    DoCmd.GoToRecord , , acPrevious

  End If

End Sub
Code:
Private Sub Go2Next_Click()

  If Me.CurrentRecord = Me.RecordsetClone.RecordCount Or Me.NewRecord = True Then
 
    MsgBox "You are on the Last Record!"

  Else

    DoCmd.GoToRecord , , acNext

  End If

End Sub


The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
Sorry...I should have said that I prefer to simply let the users know, when they try to move to the Next or Previous Record, and it is not possible, why they cannot do it. To disable the Command Buttons, as appropriate, would use similar code, like this

Code:
Private Sub Form_Current()

  If Me.CurrentRecord = 1 Then

    Me.Go2Prev.Enabled = False
    
  Else
  
    Me.Go2Prev.Enabled = True

  End If

  If Me.CurrentRecord = Me.RecordsetClone.RecordCount Or Me.NewRecord = True Then
 
    Me.Go2Next.Enabled = False
    
  Else

    Me.Go2Next.Enabled = True

  End If

End Sub

The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
Hi missinglinq

The code worked great thanks, all working now

Thanks to all for replies
 
I'm curious, is there a reason you are not using the built in form navigation controls?

I find the easiest way to give a user a uniform experience across all dataset views is using the form properties.

Allow Additions = No.
Navigation Buttons = Yes.

Every data view then works with familiar controls and no additional 'behind the form' bound event code or creating clones of any data in memory is required.

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
Hi
I did not find the controls you mentioned initially so tried with code.
The code I tried from missinglinq tells the user it is the last record which is quite useful for this purpose.

In the meantime I have found the controls you have mentioned so will try them out next time.

Thanks all
 
There is also Record Selectors, which is handy under the 'Format' tab.

You can set scrollbars, border, control box, and a whole heap of other properties for the form/window.




"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
1DMF said:
I'm curious, is there a reason you are not using the built in form navigation controls?
Many developers prefer using custom navigation buttons because the native ones are so small and hence more difficult, for a lot of users, to click on. Also, with a custom Command Button, you can provide a keyboard shortcut for the action that is visible to the user. It's all about personal preferences and the tech savvy, or lack thereof, of your end users.

The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
Thanks mssinglinq, I'm always up for learning new ways of doing something and wondered if there was a benefit in the OP's methodology.

I guess my users are used to the default navigation, so may actually get confused if I was to alter it now.



"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top