Solved

Custom Navigation Buttons

Posted on 2008-11-01
11
355 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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 - Microsoft MVP, Access and Data Platform) 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
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…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

739 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