Solved

Custom Navigation Buttons

Posted on 2008-11-01
11
337 Views
Last Modified: 2012-06-21
I have implemented custom navigation buttons as seen below.

With MS Access's navigation buttons when the user tries to move records but the current record does not have all required fields filled runtime error 3314 is reported which my form traps. However, with my navigation buttons MS access does not call error 3314 instead it calls runtime error '2105': You can't go to the specified record. How can I get my navigation buttons to act the same as MS Access's?
Private Sub cmdMoveFirst_Click()
    On Error GoTo ErrorHandler
    DoCmd.GoToRecord , , acFirst
 
Exit Sub
 
ErrorHandler:
    MsgBox Err.Description
End Sub
 
Private Sub cmdMovePrevious_Click()
    On Error GoTo ErrorHandler
    DoCmd.GoToRecord , , acPrevious
 
Exit Sub
 
ErrorHandler:
    MsgBox Err.Description
End Sub
 
Private Sub cmdMoveNext_Click()
    On Error GoTo ErrorHandler
    DoCmd.GoToRecord , , acNext
 
Exit Sub
 
ErrorHandler:
    MsgBox Err.Description
End Sub
 
Private Sub cmdMoveLast_Click()
    On Error GoTo ErrorHandler
    DoCmd.GoToRecord , , acLast
 
Exit Sub
 
ErrorHandler:
    MsgBox Err.Description
End Sub
 
Private Sub cmdAddNew_Click()
    'On Error GoTo ErrorHandler
    DoCmd.GoToRecord , , acNewRec
    
    Err.Clear
    On Error GoTo 0
    UpdateTotalRecords
    
Exit Sub
 
ErrorHandler:
    MsgBox Err.Description
End Sub

Open in new window

0
Comment
Question by:bejhan
  • 6
  • 5
11 Comments
 
LVL 75
ID: 22860262
Quick and Dirty:

Private Sub cmdMoveFirst_Click()
    On Error Resume Next                   ' ** do this on each button
    DoCmd.GoToRecord , , acFirst
    Err.Clear                                          ' ** do this on each button                            
End Sub

0
 
LVL 75
ID: 22860264
Also ... this is free and covers it:

http://www.lebans.com/recnavbuttons.htm

mx
0
 
LVL 1

Author Comment

by:bejhan
ID: 22860290
Okay going to use those buttons, only problem is (if you open frmSampleRecordNavigation) then go to the end of the records and press next a new record is created (addnew). However, once you type something in for CusName the MS Access nav addnew becomes enabled while the custom nav addnew doesn't how can I fix this?
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 75
ID: 22860476
"and press next a new record is created (addnew)."

I don't think a new record is create *until* you actually type a character in a Bound field on the form.

mx
0
 
LVL 1

Author Comment

by:bejhan
ID: 22860482
Once you type something in the bound form then access records the record and its not just a blank one right, so after that you should be able to create a blank new one with the add new button (as you can with the access nav buttons) however, these custom buttons don't do this...
0
 
LVL 75
ID: 22860486
"while the custom nav addnew doesn't how can I fix this?"

It's working correctly.  Rec 65 (new rec position) ... you type a Cust Name ... the Add New is disabled as it should be. You can hit escape to Cancel the adding of the new record. However, the Add New btn is still grayed out *because* you are still at a new record position.

mx
0
 
LVL 1

Author Comment

by:bejhan
ID: 22860488
Right, but at this point MS Access will allow you to add a new record because it recognizes that this record isn't new anymore as you have placed data into it but the custom navigation does not allow you to do this because it does not recognize that you have completed this record.
0
 
LVL 75
ID: 22860617
Not exactly. If you Escape to cancel the rec, again, you are still a new Rec position - ready for a new record to be entered.  If you type a cust name, you will see the CustID appear ... say 115.  If you hit Esc ... and then do this again, you will now see the CustID is 116 ... and so it.  So in fact, it is working correctly.

ok ...I see what you are saying. What needs to happen is the AfterUpdate of the Form need to enable to New Rec button on the Nav Subform.

Add this code to frmSampleRecordNavigation's AfterUpdate event.

Private Sub Form_AfterUpdate()
    Me.SFfrmNavButtons.Form.cmdNew.Enabled = True
End Sub

mx
0
 
LVL 1

Author Comment

by:bejhan
ID: 22862835
I tried that already, afterupdate isn't called until you tab or enter at the last field of the record. I need something that is called as soon as a change is made (not saved)
0
 
LVL 1

Author Comment

by:bejhan
ID: 22862905
"The AfterUpdate event is triggered when a control or record is updated. Within a record, changed data in each control is updated when the control loses the focus or when the user presses ENTER or TAB. When the focus leaves the record or if the user clicks Save Record on the Records menu, the entire record is updated, and the data is saved in the database."

So shouldn't the afterupdate event be called as soon as the changed control loses focus?
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 250 total points
ID: 22863052
"So shouldn't the afterupdate event be called as soon as the changed control loses focus?"

Not fhe Form's AU ..

However ... You can use the On Dirty Event - which will change as soon as any Bound control is changed.

mx
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question