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
5 6500
Obviously, you need to goto Properties - Data for the form and set AllowAdditions to No. Then -
Private Sub Go2Next_Click()
-
On Error GoTo Err_Go2Next_Click
-
-
DoCmd.GoToRecord , , acNext
-
-
Exit_Go2Next_Click:
-
Exit Sub
-
-
Err_Go2Next_Click:
-
If Err.Number = 2105 Then
-
MsgBox "This is the Last Record"
-
Else
-
MsgBox Err.Description
-
Resume Exit_Go2Next_Click
-
End If
-
End Sub
-
-
Private Sub Go2Prev_Click()
-
On Error GoTo Err_Go2Prev_Click
-
-
DoCmd.GoToRecord , , acPrevious
-
-
Exit_Go2Prev_Click:
-
Exit Sub
-
-
Err_Go2Prev_Click:
-
If Err.Number = 2105 Then
-
MsgBox "This is the First Record"
-
Else
-
MsgBox Err.Description
-
Resume Exit_Go2Prev_Click
-
End If
-
End Sub
Linq ;0)>
Doh, i knew it would be a simple fix.
Thanks alot
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: -
Private Sub Form_Current()
-
Dim recClone As DAO.Recordset
-
-
Set recClone = Me.RecordsetClone
-
-
recClone.Bookmark = Me.Bookmark 'must synchronize
-
-
recClone.MovePrevious
-
Me![cmdPrevious].Enabled = Not (recClone.BOF)
-
recClone.MoveNext
-
-
recClone.MoveNext
-
Me![cmdNext].Enabled = Not (recClone.EOF)
-
recClone.MovePrevious
-
End Sub
Yeah that works well to, nice work
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. - Private Sub Go2First_Click()
-
On Error GoTo Err_Go2First_Click
-
-
DoCmd.GoToRecord , , acFirst
-
-
Exit_Go2First_Click:
-
-
Exit Sub
-
-
Err_Go2First_Click:
-
-
MsgBox Err.Description
-
-
Resume Exit_Go2First_Click
-
-
End Sub
-
-
Private Sub Go2Last_Click()
-
On Error GoTo Err_Go2Last_Click
-
-
DoCmd.GoToRecord , , acLast
-
-
Exit_Go2Last_Click:
-
-
Exit Sub
-
-
Err_Go2Last_Click:
-
-
MsgBox Err.Description
-
-
Resume Exit_Go2Last_Click
-
-
End Sub
-
-
Private Sub Go2Next_Click()
-
-
On Error GoTo Err_Go2Next_Click
-
-
DoCmd.GoToRecord , , acNext
-
-
Exit_Go2Next_Click:
-
-
Exit Sub
-
-
Err_Go2Next_Click:
-
-
If Err.Number = 2105 Then
-
-
DoCmd.GoToRecord , , acFirst
-
-
Else
-
-
MsgBox Err.Description
-
Resume Exit_Go2Next_Click
-
-
End If
-
-
End Sub
-
-
Private Sub Go2Prev_Click()
-
On Error GoTo Err_Go2Prev_Click
-
-
DoCmd.GoToRecord , , acPrevious
-
-
Exit_Go2Prev_Click:
-
-
Exit Sub
-
-
Err_Go2Prev_Click:
-
-
If Err.Number = 2105 Then
-
-
DoCmd.GoToRecord , , acLast
-
-
Else
-
-
MsgBox Err.Description
-
Resume Exit_Go2Prev_Click
-
-
End If
-
-
End Sub
Linq ;0)> Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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
...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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
|
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...
|
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,...
|
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...
|
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...
| |