473,388 Members | 1,215 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Custom Record Navigation Buttons

365 100+
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
5 6500
missinglinq
3,532 Expert 2GB
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
Dan2kx
365 100+
Doh, i knew it would be a simple fix.

Thanks alot
Dec 22 '07 #3
ADezii
8,834 Expert 8TB
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
Dan2kx
365 100+
Yeah that works well to, nice work
Dec 22 '07 #5
missinglinq
3,532 Expert 2GB
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

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

Similar topics

0
by: Carl | last post by:
I have a main form with navigation buttons on it and a label showing for example Record 1 of 15 using recordsetclone on it and eveything works fine. When I move through the records the record...
1
by: Robert Neville | last post by:
I am having some trouble with some old code revolving around custom form navigation buttons. My main form has a sub-form with these custom navigation buttons. In other words, the code should be...
15
by: Steve | last post by:
I have a form with about 25 fields. In the BeforeUpdate event of the form, I have code that sets the default value of each field to its current value. For a new record, I can put the focus in any...
0
by: misscrf | last post by:
I am currently working on a database, in 3rd normal form, which is for candidates who apply for a job with the law firm that I workd for. My issue is with good form design. I have a main...
2
by: asad | last post by:
hello friends, how ru all I want to create a custom paging logic in ASP.NET with a next link for example if i have 100 pages record so i want to show 6 pages link on page one and next link ...
6
by: John | last post by:
Hi I need to block user from moving away from a record using any of First/Last/Prev/Next/New Record or any other way IF the record has not been saved, and displaying a message to the effect...
4
by: aaronyoung | last post by:
I have created custom navigation buttons and Record Number indicators on several forms that are used to review and update records based on a query. My On Current event to update the "Record X of...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.