By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,493 Members | 1,208 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,493 IT Pros & Developers. It's quick & easy.

Custom Record Navigation Buttons

100+
P: 365
Hello again,

I have a new problem to tackle,

I Have a form which is used for adding staff members, and because i like to reuse forms, i have set it to open in add mode or in edit mode using a simple string from my custom switchboard. so when it is in edit mode the forms record source is a parameter query that forces the user to search by surname (and forces a wildcard), if the query returns more than one result (which is possible obviously) i want the user to be able to cycle the available records,

i have to buttons: next and previous with the:
docmd.gotorecord, , acnext / ac previous.

i dont want the user to be able to add new users (which is possible) and i want to stop the error (which i can do myseff with an on error statement,)

how would i go about this then?
i am thinking along the lines of

if first record then
msgbox "no more records"

etc

Thanks to any that can help me!
Dan
Dec 22 '07 #1
Share this Question
Share on Google+
5 Replies


missinglinq
Expert 2.5K+
P: 3,532
Obviously, you need to goto Properties - Data for the form and set AllowAdditions to No. Then
Expand|Select|Wrap|Line Numbers
  1. Private Sub Go2Next_Click()
  2. On Error GoTo Err_Go2Next_Click
  3.  
  4.    DoCmd.GoToRecord , , acNext
  5.  
  6. Exit_Go2Next_Click:
  7.     Exit Sub
  8.  
  9. Err_Go2Next_Click:
  10. If Err.Number = 2105 Then
  11.    MsgBox "This is the Last Record"
  12. Else
  13.     MsgBox Err.Description
  14.     Resume Exit_Go2Next_Click
  15. End If
  16. End Sub
  17.  
  18. Private Sub Go2Prev_Click()
  19. On Error GoTo Err_Go2Prev_Click
  20.  
  21. DoCmd.GoToRecord , , acPrevious
  22.  
  23. Exit_Go2Prev_Click:
  24.     Exit Sub
  25.  
  26. Err_Go2Prev_Click:
  27. If Err.Number = 2105 Then
  28.     MsgBox "This is the First Record"
  29. Else
  30.     MsgBox Err.Description
  31.     Resume Exit_Go2Prev_Click
  32. End If
  33. End Sub
Linq ;0)>
Dec 22 '07 #2

100+
P: 365
Doh, i knew it would be a simple fix.

Thanks alot
Dec 22 '07 #3

ADezii
Expert 5K+
P: 8,597
Hello again,

I have a new problem to tackle,

I Have a form which is used for adding staff members, and because i like to reuse forms, i have set it to open in add mode or in edit mode using a simple string from my custom switchboard. so when it is in edit mode the forms record source is a parameter query that forces the user to search by surname (and forces a wildcard), if the query returns more than one result (which is possible obviously) i want the user to be able to cycle the available records,

i have to buttons: next and previous with the:
docmd.gotorecord, , acnext / ac previous.

i dont want the user to be able to add new users (which is possible) and i want to stop the error (which i can do myseff with an on error statement,)

how would i go about this then?
i am thinking along the lines of

if first record then
msgbox "no more records"

etc

Thanks to any that can help me!
Dan
These Buttons should not be Enabled under these conditions, and the User should not have the Option of clicking on them. If the User is on the First Record, the Previous Button should be disabled, if he is on the Last, the Next Button should be disabled. Placing this code in the Form's Current() Event will set this up for you, if you wish to:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. Dim recClone As DAO.Recordset
  3.  
  4. Set recClone = Me.RecordsetClone
  5.  
  6. recClone.Bookmark = Me.Bookmark    'must synchronize
  7.  
  8. recClone.MovePrevious
  9.   Me![cmdPrevious].Enabled = Not (recClone.BOF)
  10. recClone.MoveNext
  11.  
  12. recClone.MoveNext
  13.   Me![cmdNext].Enabled = Not (recClone.EOF)
  14. recClone.MovePrevious
  15. End Sub
Dec 22 '07 #4

100+
P: 365
Yeah that works well to, nice work
Dec 22 '07 #5

missinglinq
Expert 2.5K+
P: 3,532
And since this thread has such a descriptive title, and people researching the topic may end up here, I'll list code for a suite of navigation buttons I usually use. As with the other code listed here, the form's AllowAdditions Property has to be set to No.

Rather than disabling the appropriate nav button when reaching the beginning or end of the record set, the Next and Previous buttons here causes the user to "wrap" around. If on the first record and Previous is hit, it "wraps" around to the last record; if on the last recrord and Next is hit, it "wraps" around to the first record.


Expand|Select|Wrap|Line Numbers
  1. Private Sub Go2First_Click()  
  2. On Error GoTo Err_Go2First_Click
  3.  
  4. DoCmd.GoToRecord , , acFirst    
  5.  
  6. Exit_Go2First_Click:
  7.  
  8. Exit Sub     
  9.  
  10. Err_Go2First_Click:        
  11.  
  12. MsgBox Err.Description
  13.  
  14. Resume Exit_Go2First_Click
  15.  
  16. End Sub    
  17.  
  18. Private Sub Go2Last_Click()
  19. On Error GoTo Err_Go2Last_Click
  20.  
  21. DoCmd.GoToRecord , , acLast     
  22.  
  23. Exit_Go2Last_Click:        
  24.  
  25. Exit Sub
  26.  
  27. Err_Go2Last_Click:
  28.  
  29. MsgBox Err.Description      
  30.  
  31. Resume Exit_Go2Last_Click
  32.  
  33. End Sub
  34.  
  35. Private Sub Go2Next_Click()
  36.  
  37. On Error GoTo Err_Go2Next_Click
  38.  
  39. DoCmd.GoToRecord , , acNext
  40.  
  41. Exit_Go2Next_Click:
  42.  
  43. Exit Sub
  44.  
  45. Err_Go2Next_Click:
  46.  
  47.   If Err.Number = 2105 Then
  48.  
  49.    DoCmd.GoToRecord , , acFirst
  50.  
  51.   Else
  52.  
  53.    MsgBox Err.Description
  54.    Resume Exit_Go2Next_Click
  55.  
  56.   End If
  57.  
  58. End Sub
  59.  
  60. Private Sub Go2Prev_Click()
  61. On Error GoTo Err_Go2Prev_Click
  62.  
  63. DoCmd.GoToRecord , , acPrevious 
  64.  
  65. Exit_Go2Prev_Click:
  66.  
  67. Exit Sub
  68.  
  69. Err_Go2Prev_Click:
  70.  
  71. If Err.Number = 2105 Then
  72.  
  73.   DoCmd.GoToRecord , , acLast
  74.  
  75. Else
  76.  
  77.   MsgBox Err.Description
  78.   Resume Exit_Go2Prev_Click
  79.  
  80.   End If
  81.  
  82. End Sub
Linq ;0)>
Dec 22 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.