Is there an event for moving from one record to the next

jpl458

Well-known member
Local time
Yesterday, 16:09
Joined
Mar 30, 2012
Messages
1,218
I have a form that allows the user to scroll through the records using the < > at the bottom of the form. The question is, is there an event that fires on changinh to a new record while scrolling. I've tried the after update, before update, all to no avail.

Thanks
 
That would be "On Current" IF you give a record the focus. If you are only scrolling, you are simply moving the pictures around on the screen, so you don't get a per record event.

However, there are mouse mouse events that respond to the mouse position as it changes. However, I'm not sure how that would help. What is the goal here? What do you need to have happen? and why?
 
You can always change the forms default view from single to continous and set the forms Scroll Bars property to vertical or horizontal or both. Also, you can use:
DoCmd.GoToRecord acActiveDataObject, , acNext
with any controls On Click Event or any other Event.
 
That would be "On Current" IF you give a record the focus. If you are only scrolling, you are simply moving the pictures around on the screen, so you don't get a per record event.

However, there are mouse mouse events that respond to the mouse position as it changes. However, I'm not sure how that would help. What is the goal here? What do you need to have happen? and why?
I was waiting for the Why question. The application is a bit weird and unconventional. I have a form that looks like a data entry form, but data entry is turned off. There is not a lot of data. In textbox controls on the form, in lost focus events, I can open combo boxes that allow users to select items that may be needed to added to the record. When I go to the next record, I want to have the popup boxes vanish and revert to null. I have the code to do that, but it would be handy to have when I change from one record to the next. Based on your answer, how would I give the current record the focus in such a layout. I could close the popups as I leave them, but it would helpful if they could be seen till I go to the next record. Hope this make s modicum of sense.

Thanks
 
There is no next or previous record in a database. There is just a set of records which is ordered in an arbitrary (or determined) order. So if your form has the enter key behaviour set to active record, or current record (I forget the term off hand) the recordset cursor stays on the current record. If it's set to next record the cursor moves to the next record according to the active index of the recordset, after you leave the last field in the declared tab order.

When you reach a new record, the current event fires, so you can use that event to initialise the status of the "new" record

You even have a "me.newrecord" boolean to test whether you have reached a new record, or you are examining an existing record.
 
You can always change the forms default view from single to continous and set the forms Scroll Bars property to vertical or horizontal or both. Also, you can use:
DoCmd.GoToRecord acActiveDataObject, , acNext
with any controls On Click Event or any other Event.
I just added record navigation buttons to the form and can control thing in those, I think. Not elegant, but workable.
 
I was waiting for the Why question. The application is a bit weird and unconventional. I have a form that looks like a data entry form, but data entry is turned off. There is not a lot of data. In textbox controls on the form, in lost focus events, I can open combo boxes that allow users to select items that may be needed to added to the record. When I go to the next record, I want to have the popup boxes vanish and revert to null. I have the code to do that, but it would be handy to have when I change from one record to the next. Based on your answer, how would I give the current record the focus in such a layout. I could close the popups as I leave them, but it would helpful if they could be seen till I go to the next record. Hope this make s modicum of sense.

Thanks
Data entry is disabled, but you still want to update the records. ;)

Scrolling itself isn't going to work, but there are other ways to move focus from one record to the next.... and while I was typing you discovered the record navigations buttons. (y)
 
There is no next or previous record in a database. There is just a set of records which is ordered in an arbitrary (or determined) order. So if your form has the enter key behaviour set to active record, or current record (I forget the term off hand) the recordset cursor stays on the current record. If it's set to next record the cursor moves to the next record according to the active index of the recordset, after you leave the last field in the declared tab order.

When you reach a new record, the current event fires, so you can use that event to initialise the status of the "new" record

You even have a "me.newrecord" boolean to test whether you have reached a new record, or you are examining an existing record.
Do I need to set the behavior of the enter key for current event fires?
 
Data entry is disabled, but you still want to update the records. ;)

Scrolling itself isn't going to work, but there are other ways to move focus from one record to the next.... and while I was typing you discovered the record navigations buttons. (y)
Something about Great Minds, is involved here. Like the thumbs up, gave me the warm and fuzzies (Old IBM term)
 
I just added record navigation buttons to the form and can control thing in those, I think. Not elegant, but workable.
It is not the navigation buttons that give you control, it is the form level event procedures that give you control over how a form behaves.

There is no event that fires when you leave a record. There are events that fire when a record is dirty and needs to be saved (the form's BeforeUpdate event) That keeps you from leaving an incomplete record or one with invalid data. There is an event that fires when a new record gets the focus and that is the form's Current event. That event is typically used to show/hide controls based on some data value in the current record.

Most of the time, you don't want the user to accidentally scroll to a new record so you would set the Cycle property to Current record. I ALWAYS use this setting for single record and I usually use it for continuous forms. This prevents the tab key or enter key from changing the current record. The only way to move to a new record is by using the built in navigation buttons or clicking into a different row.

Do I need to set the behavior of the enter key for current event fires?
No, do NOT change the behavior of the enter key. Control the scrolling by setting the Cycle property as I described above to force the user to use the navigation control. You do NOT need to create your own navigation control. It isn't any better or more user friendly than the built in option but it may look nicer so use your own controls if you want. Just make sure you download a version that lets you reuse the controls on all forms without having to write code for each instance.
 
It is not the navigation buttons that give you control, it is the form level event procedures that give you control over how a form behaves.

There is no event that fires when you leave a record. There are events that fire when a record is dirty and needs to be saved (the form's BeforeUpdate event) That keeps you from leaving an incomplete record or one with invalid data. There is an event that fires when a new record gets the focus and that is the form's Current event. That event is typically used to show/hide controls based on some data value in the current record.

Most of the time, you don't want the user to accidentally scroll to a new record so you would set the Cycle property to Current record. I ALWAYS use this setting for single record and I usually use it for continuous forms. This prevents the tab key or enter key from changing the current record. The only way to move to a new record is by using the built in navigation buttons or clicking into a different row.


No, do NOT change the behavior of the enter key. Control the scrolling by setting the Cycle property as I described above to force the user to use the navigation control. You do NOT need to create your own navigation control. It isn't any better or more user friendly than the built in option but it may look nicer so use your own controls if you want. Just make sure you download a version that lets you reuse the controls on all forms without having to write code for each instance.
Whatever happens, if I create navigation buttons, is the same for each button. I was going to create a subroutine or a module that does the cleanup, that way I won't have to code for each. But the Current event seems better. Mostly because you say it is, and after rereading it, it makes more sense. Only one place to put the code for everything I need. And, no need to clutter up the screen with more controls.

Thanks again, Pat

BTW, the note you sent regarding the similarity of the forms class module and the mainline of a linear language was helpful.
 
BTW, the note you sent regarding the similarity of the forms class module and the mainline of a linear language was helpful.
Thanks. That analogy doesn't help people who have no programming experience but that epiphany really helped me when it came to me after a year or two of struggling to figure out how to actually use the event model to my advantage instead of feeling like I was fighting an uphill battle:) I'm glad you found it helpful. Just remember there is almost certainly ONE SINGLE event that will solve your problem. You just have to figure out what that event is:) Sometimes, it will seem like the choice of events is equal but when you dig deeply, it is almost never equal. One will surely be better than another. For example, I had one person argue with me about why he thought the lost focus event was the "correct" event for validation because he liked the idea that Access wouldn't let you leave the control. That's why I made it the star of the second video where I show how that event fails to stop Access from saving invalid data no matter how promising it looks on the surface.

I don't know if you ever saw this thread but if you haven't seen it, do take a look. Building this sample to show WHY the BeforeUpdate event is the best event for data validation actually was an eye opener for me. There are two videos which have gotten good reviews based on my PM's. The database I used is a recent addition to the thread. you can use the forms I used in the videos or you can make your own to test specific circumstances.

 
Thanks. That analogy doesn't help people who have no programming experience but that epiphany really helped me when it came to me after a year or two of struggling to figure out how to actually use the event model to my advantage instead of feeling like I was fighting an uphill battle:) I'm glad you found it helpful. Just remember there is almost certainly ONE SINGLE event that will solve your problem. You just have to figure out what that event is:) Sometimes, it will seem like the choice of events is equal but when you dig deeply, it is almost never equal. One will surely be better than another. For example, I had one person argue with me about why he thought the lost focus event was the "correct" event for validation because he liked the idea that Access wouldn't let you leave the control. That's why I made it the star of the second video where I show how that event fails to stop Access from saving invalid data no matter how promising it looks on the surface.

I don't know if you ever saw this thread but if you haven't seen it, do take a look. Building this sample to show WHY the BeforeUpdate event is the best event for data validation actually was an eye opener for me. There are two videos which have gotten good reviews based on my PM's. The database I used is a recent addition to the thread. you can use the forms I used in the videos or you can make your own to test specific circumstances.

If I could, I would give you an apple.
You gave me my Sunday Morning assignment
 
BTW, the answer to the BAL puzzle is:

XOR a,b
XOR b,a
XOR a,b
Swaps the 2 fields without using a 3rd field
XOR in VB does not work quite the same way, I think.
 
I do virtually no bit manipulation so although I know that XOR exists, I don't believe I've ever used it in any program I've written in 50 + years:) I've AND'd bits because Microsoft assigns meaning to individual bits in certain operations but never had to remove them or swap them. In the relational universe, this would be the equivalent of mushing attributes together into a single field which would make it non atomic and therefore violate first normal form.
 
Used the current event and it was perfect.
 
BTW, the answer to the BAL puzzle is:

XOR a,b
XOR b,a
XOR a,b
Swaps the 2 fields without using a 3rd field
XOR in VB does not work quite the same way, I think.
That's clever. Xor would work correctly in VB
A= 11
B= 00

Xor a,b a=11 (Syntax would be a= a xor b)
Xor b,a b= 11
Xor a,b a=00

Not a proof, but a slick process.

I use XOR in simple encryption.
A xor bitmask = B
B xor bitmask = A
 
I do virtually no bit manipulation so although I know that XOR exists, I don't believe I've ever used it in any program I've written in 50 + years:) I've AND'd bits because Microsoft assigns meaning to individual bits in certain operations but never had to remove them or swap them. In the relational universe, this would be the equivalent of mushing attributes together into a single field which would make it non atomic and therefore violate first normal form.

True, in relational universes you don't likely use XOR - or any of the other Boolean operators - in bitwise fashion. However, if your non-SQL but related programming (including VBA) ever gets back a status code, there is a non-zero chance that some part of it will be bit-encoded. For instance, user file permissions when using a FileSystemObject to get a file's attributes. There would be a chance in that case to use bit-twiddler operators. OK, granted, not usually done that often - but not unheard of.

And for what it's worth, bit-wise or not, XOR is useful to test whether something with two incompatible alternatives is in an erroneous state using only a single test action.

Back in the 1970s, XOR was essential for me because device-driver code with any device that has typical status registers will almost certainly need to do some serious bit twiddling. At the time, I was doing device drivers for RSX-11M operating system and our company's proprietary devices.
 
ever gets back a status code, there is a non-zero chance that some part of it will be bit-encoded.
I do believe I mentioned that.
 
If I could, I would give you an apple.
You gave me my Sunday Morning assignment
Minor epiphany. The events in ACCESS are like user exits that came in older software. Early versions of IBM's supervisors had user exits, as I remember from the ferrite core days, or I might be confusing it with other software. i ts a a place in an application where you could put a bit of your own , custom code, to augment the application to your fancy.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom