Solved

Custom Navigation Buttons

Posted on 2008-11-01
11
329 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
 
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
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.

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now