Solved

MS Access - Record navigation

Posted on 2012-12-29
8
569 Views
Last Modified: 2012-12-29
Is it possible to trap or detect that the record navigation buttons have been clicked with the mouse?

On a few of the forms  I need to know when the user navigates to a NEW record through either the > or >* button.

I haven't found a way to detect they have been used.  The users are used to being able to navigate through the records with the buttons but in a few cases a new record needs some initialization before the user can enter data.

If I can't detect the click can I prevent the user from navigating to a new record?
The forms have an ADD RECORD button that provides the initialization through code before the user can enter data.

mlmcc
0
Comment
Question by:mlmcc
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 29

Accepted Solution

by:
IrogSinta earned 350 total points
ID: 38729808
Setting the AllowAdditions property of the form to No will prevent them from navigating to a new record.
0
 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Access MVP)
DatabaseMX (Joe Anderson - Access MVP) earned 100 total points
ID: 38729814
In the Current event of a Form, you can test for a New Record:

If Me.NewRecord = True then
   ' do something
Else
   'do something else
End If

mx
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38729818
Alternatively, you can add a check on the form's OnCurrent event like so:
If NewRecord Then 
    Call Initialize routine
End If

Open in new window

0
 
LVL 47

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 50 total points
ID: 38729855
As MX and IrogSinta have said, to detect a new record, use the Form_Current event  and the NewRecord property of the Form.

Occassionally, you will find that you need some functionality to occur before the user leaves the current record.  If there have been no changes to that record then the Form_AfterUpdate event will not fire, so you may end up creating your own set of navigation buttons.  I usually put mine in the Forms footer and turn off the default navigation buttons.

You will also find this technique handy if you do any work with unbound forms.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 30

Expert Comment

by:hnasr
ID: 38730273
Try this:
declare a global variable in a module
Set global variable to true if button clicked
In Form_Current event check for global variable and use your initialization code if true, then set to false

Global bln_navigation As Boolean ' in a module

Private Sub Command22_Click() 'the button to navigate or to add
    bl_navigation = True
    DoCmd.GoToRecord , , acNext
End Sub

Private Sub Form_Current()
    If bln_navigation = True Then 'got here through button
        'your code here
        bln_navigation = False
    End If
End Sub 

Open in new window

0
 
LVL 100

Author Closing Comment

by:mlmcc
ID: 38730297
IrogSinta - A simple solution.  I just had to add code to the ADD/New record button to allow additions and turn it off when they saved the record.

 DatabaseMX - Your method would work but a little more involved than I wanted to do.

 fyed -  Good additional information.

increased points to 500

mlmcc
0
 
LVL 75
ID: 38730302
" but in a few cases a new record needs some initialization before the user can enter data."
Which is exactly what I posted ... so, I guess I'm confused.
0
 
LVL 100

Author Comment

by:mlmcc
ID: 38730310
I just found it easier to do all the code behind the ADD/NEW record button rather than adding code to the form's OnCurrent event.

mlmcc
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

746 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

15 Experts available now in Live!

Get 1:1 Help Now