Full Version: What Event To Check Form Record B4 Moving To New Record When No Change To Record Moved From
UtterAccess Forums > Microsoft® Access > Access Forms
catbeasy
Sorry for the long topic, but unsure how else to articulate this.

Basically, when I'm on record 'A' and want to move to Record 'B', my understanding is that if I've made changes to 'A', the before update event will fire and I can do something with code. However..

What if I've not made any changes to record 'A'? I still want some way to check record 'A' before moving onto record 'B'.

I almost expect an event like "Before Moves To New Record" or some such thing that will fire regardless or only when there are no changes to the current record, before moving to a subsequent record..does this already exist? None of the current event selections seem to offer this..but maybe I'm just missing something obvious?

I know I could do this with a navigation macro button, possibly by getting rid of Access's native nav buttons and forcing the use of the nav macro button, but wanted to know if there's another way to do it without resorting to this..

Thanks for any suggestions!
Larry Larsen
Hi

Still using the "Before Update" event you can do a check/validation to see if the record has been changed..

With some thing like this :
CODE
' This procedure checks to see if the data on the form has
' changed. If the data has changed, the procedure prompts the
' user to continue with the save operation or to cancel it. Then
' the action that triggered the BeforeUpdate event is completed.

Dim ctl As Control

On Error GoTo Err_BeforeUpdate

' The Dirty property is True if the record has been changed.

If Me.Dirty Then

    ' Prompt to confirm the save operation.

    If MsgBox("Do you want to save?", vbYesNo + vbQuestion, _
              "Save Record") = vbNo Then

        Me.Undo

    End If
End If

Exit_BeforeUpdate:

Exit Sub

Err_BeforeUpdate:

MsgBox Err.Number & " " & Err.Description

Resume Exit_BeforeUpdate


HTH's
thumbup.gif
catbeasy
Actually I want my code to kick off whether or not the record has changed.

So, if a record was entered successfully yesterday and I go back into it today and nothing is changed in the record (and no other code kicks off from navigating TO the record) then using the before update event will not work. Its my understanding that the Before Update event only kicks off when a change is made to the record. In this case no change is made and so the Before Update event is never accessed..

I even tried your code in the before update event and it did not work. Again, wouldn't expect it to if what I said above is correct, unless I'm missing something?

This is from msdn:

"The BeforeUpdate event occurs before changed data in a control or record is updated"

Pretty explicit that the record has to be changed..

(https://msdn.microsoft.com/en-us/library/office/ff822421.aspx)
Larry Larsen
Hi
We/I need to understand what you mean by:
QUOTE
What if I've not made any changes to record 'A'? I still want some way to check record 'A' before moving onto record 'B'.


What would that "check" be..??
thumbup.gif
catbeasy
The db was created by someone a long time ago. There was no validation when created. The users want to navigate through all the existing records and get messages when fields that are supposed to be filled out are not filled out (they do not want us doing any potential updates).

The ON Current event would be fine for this. However, the way the db was designed, there are updates that are made to tables that are not underlying what's in the form. As a result, if the user makes a change to one of these items, the changes occur to these other tables that the form, once refreshed will now reflect, but in order to make the change in the first place, the record had to be saved.

So when you navigate to another record, since the changes to these other tables have already been saved and the form just reflects these changes, no new change registers (the record has already been saved) occurs in the form itself when navigating and so the before update event never kicks off.

I think the solution is to go to where the changes are being attempted and code there, but thought I could do it all in one go with some kind of "Before Navigating to another record, regardless of changes to form being made" event..

Thanks..
Larry Larsen
Hi
Thanks for the details, yes that would become an impossible scenario unless you have some thing to compare..
thumbup.gif
gemmathehusky
QUOTE
The ON Current event would be fine for this. However, the way the db was designed, there are updates that are made to tables that are not underlying what's in the form. As a result, if the user makes a change to one of these items, the changes occur to these other tables that the form, once refreshed will now reflect, but in order to make the change in the first place, the record had to be saved.


this confuses me. Can you clarify the circumstance in which a record can change without changing ....

the underlying paradigm for a database is that anything can change at any time. If you do not change a record, what is the point of checking the record again? There is no event to do this, because there is no update, as far as I can see. That's the way access works. When you leave a changed (dirty) record the change is committed to the database. When you leave an unedited record, no event happens.

If you want to track changes, I would have thought a better process would be to include an audit log, and then examine the log for changes you might be interested in.
Larry Larsen
Hi Dave

My take on the situation is data has been added/modified at table level and the OP is asking how can those changes be captured at form level..

Yes... audit trails can be the most effective method of capturing those changes at form level, and would encourage this procedure in all input applications.

thumbup.gif
missinglinq
QUOTE (catbeasy)
...The users want to navigate through all the existing records and get messages when fields that are supposed to be filled out are not filled out...


Sounds to me like the best approach would be to

  1. Create a Query to pull all Records where the Fields in question are Null
  2. Base a Form on this Query
  3. Go through the Records, filling in the needed data.
Using this Form, you'd only have to slog your way through errant Records, not every Record in the underlying record source.

You'd probably need to do validation in the BeforeUpdate event of this Form, to make sure, this time, that all information is entered.

Linq ;0)>
catbeasy
Certain changes are registered to tables that are not part of the underlying data source of the form. When these changes are made, they do not register as any kind (before or after update) of event per the form. So when making these kind of changes, the form’s before/after update events do not kick off.
catbeasy
Missingling..

Yes, I think this would be the best way as well..I just wanted to try and incorporate something like this with the form..which again, I can do. I just have to add my own navigation buttons..which is what I was trying to avoid if possible..

Btw, this editor is going crazy! It only lets me enter characters intermittently. I start to type, it will do the first characters then nothing and then I keep hitting the keyboard and eventually after about 7 or 8 tries, it will type another character and then not again. I had to type these responses in notepad..! Never had this issue on UtterAccess before..
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.