Was there a change?

  • Thread starter Thread starter John
  • Start date Start date
J

John

I have a form (frmActMapUpt) that allows the users to update sorting and
grouping coding in a table. If they update anything, I have to run a few
"house-keeping" queries, if they just look at the data in the table and don't
change anything, I would like to skip the house-keeping because they take
some time to run.

Is there a way to know if a value in any field was changed?
 
John said:
I have a form (frmActMapUpt) that allows the users to update sorting and
grouping coding in a table. If they update anything, I have to run a few
"house-keeping" queries, if they just look at the data in the table and
don't
change anything, I would like to skip the house-keeping because they take
some time to run.

Is there a way to know if a value in any field was changed?


If the record was changed by the form, the form's AfterUpdate event will
fire. If the record was deleted, the form's Delete event will fire, as well
as (usually) the form's BeforeDelConfirm and AfterDelConfirm events.
 
Dirk,
Thanks for the feedback. I really need this to be a "switch" that will run
when they close the form (on the unload event). This is a continuous form,
so the could edit several records. I need to do the house-keeping if any one
record is changed, when they close the form. Wouldn't the "AfterUpdate()"
event fire when they went to the next record? Could I put some vba in the
"AfterUpdate()" event that captures an variable switch that the unloadform
event then can read as true / false?
 
Create a form module level boolean variable that you can use to determine if
any changes have been made. Then, depending on where you need record that,
set the varialbe so a value that will tell you it has changes. The form
After Update event may suffice as it will only fire if changes have been made
to a record, but that means any change. If you want to track specific
fields, you may need to do it differently. Lastly, in the form's unload
event, check the variable to see if changes have been made and if so, do your
housekeeping.
 
John said:
Dirk,
Thanks for the feedback. I really need this to be a "switch" that will
run
when they close the form (on the unload event). This is a continuous
form,
so the could edit several records. I need to do the house-keeping if any
one
record is changed, when they close the form.
Gotcha.

Wouldn't the "AfterUpdate()" event fire when they went to the next record?
Yes.

Could I put some vba in the
"AfterUpdate()" event that captures an variable switch that the unloadform
event then can read as true / false?

Easily. You'd have a module-level boolean variable that you'd set in the
form's AfterUpdate event, and then use the form's Unload or Close event to
check that variable and do your housekeeping. For example:

'----- start of example code for form's module -----
Option Compare Database
Option Explicit

Dim mblnRecordsUpdated As Boolean


Private Sub Form_AfterUpdate()

mblnRecordsUpdated = True

End Sub


Private Sub Form_Close()

If mblnRecordsUpdated Then

' ... housekeeping code goes here ...

End If

End Sub
'----- end of example code -----

I chose the Close event, rather than the Unload event, because I don't
anticipate cancelling the close and keeping the form open. If your
housekeeping code may determine that the form shouldn't close, you'll have
to use the Unload event, which can be cancelled.
 
Dirk Goldgar said:
I chose the Close event, rather than the Unload event, because I don't
anticipate cancelling the close and keeping the form open. If your
housekeeping code may determine that the form shouldn't close, you'll have
to use the Unload event, which can be cancelled.


It just occurred to me that the variable may already have been cleared in
the form's Close event. If that turns out to be the case, you'll have to
use the Unload event after all.
 
Dirk,
Thanks for the feedback. I really need this to be a "switch" that will run
when they close the form (on the unload event). This is a continuous form,
so the could edit several records. I need to do the house-keeping if any one
record is changed, when they close the form. Wouldn't the "AfterUpdate()"
event fire when they went to the next record? Could I put some vba in the
"AfterUpdate()" event that captures an variable switch that the unloadform
event then can read as true / false?

You might want to put a module-level variable in the Form's Module by putting

Dim IsModified As Boolean

above any of the Subs, right under the Option Explicit line at the top of the
module. Set it to True in the form's AfterUpdate event (which will fire if
they modify anything), and check it in the form's Close or Unload event.
 
Back
Top