Test form for changes on close

J

JHB

Hi:

I would like to be able to test a form for changes when it is closed.
There are about 20 fields, and a change in any one will require
testing and recalculation which I do not wish to do if it isnt
necessary. Is there some simple way to test when a form is closed and
get a special response ONLY if a change has been made in the data? I
can think of a way. but it requires triggers in all fields (on
change) which will set an indicator that there had been a change in
the form content. You then test the trigger on form close, only doing
recalculation if it indicates a change has taken place.

I feel there must be a simpler way


Any suggestion much appreciated.

John Baker
 
A

Access Developer

The Form's Dirty property indicates a change has been made to the data
originally read and displayed on the Form for the Record.

It is often more useful to place the recalculation code in the AfterUpdate
event of a Control that requires recalculation. If the recalculations on
your Form are required for any Control being changed, and do not affect any
other calculations during process of the form, the Form's Dirty property
would be more efficient.
 
J

JHB

The Form's Dirty property indicates a change has been made to the data
originally read and displayed on the Form for the Record.

It is often more useful to place the recalculation code in the AfterUpdate
event of a Control that requires recalculation.  If the recalculations on
your Form are required for any Control being changed, and do not affect any
other calculations during process of the form, the Form's Dirty property
would be more efficient.

 --
 Larry Linson
  Microsoft Office Access MVP
  Co-Author, Microsoft Access Small Business Solutions, Wiley 2010

Thank you -- most helpful. One further question however: At what point
does the "Forms Dirty" trigger off? I only want to recalc once no
matter how many changes there are in underlying data so I am looking
for something that will trigger ONLY when the form is closed. Does
"Dirty" do it for me?

Thanks again

John Baker
 
A

Access Developer

The Form is set "Dirty" when any Control on the Form is changed. However,
you can check the property when you wish --only before saving the Record, or
only before Closing the Form, in the Event Procedure for those actions.

Note that is not pertinent to your situation, but can be useful: A "trick"
that can be used to force saving the Record displayed in a Form is to
execute the VBA code "Me.Dirty = False".

--
Larry Linson
Microsoft Office Access MVP
Co-Author, Microsoft Access Small Business Solutions, Wiley 2010

The Form's Dirty property indicates a change has been made to the data
originally read and displayed on the Form for the Record.

It is often more useful to place the recalculation code in the AfterUpdate
event of a Control that requires recalculation. If the recalculations on
your Form are required for any Control being changed, and do not affect
any
other calculations during process of the form, the Form's Dirty property
would be more efficient.

Thank you -- most helpful. One further question however: At what point
does the "Forms Dirty" trigger off? I only want to recalc once no
matter how many changes there are in underlying data so I am looking
for something that will trigger ONLY when the form is closed. Does
"Dirty" do it for me?

Thanks again

John Baker
 
B

Bob Quintal

Thank you -- most helpful. One further question however: At what
point does the "Forms Dirty" trigger off? I only want to recalc
once no matter how many changes there are in underlying data so I
am looking for something that will trigger ONLY when the form is
closed. Does "Dirty" do it for me?

Thanks again

John Baker

You misunderstand the .dirty property. It is not an Event.
In the form's close event you would test if the form is dirty and run
the calculations, otherwise there is no need.

Actually you will want to use the form's Before_update event do do
the recalculation, so to have the recalculation saved as well as the
changes, Form_Close is too late.

Code would look like

Private Sub Form_BeforeUpdate(Cancel As Integer)

If me.Dirty then
' do what you need to recalculate and
' put the new value in the textbox
End If
Exit Sub
End Sub
 
J

John W. Vinson

You misunderstand the .dirty property. It is not an Event.

Quibble: there IS a Dirty event, as well as a Dirty property - but Bob's right
that:
In the form's close event you would test if the form is dirty and run
the calculations, otherwise there is no need.

So you would not need any code in the Form's Dirty event.
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 
J

JHB

Quibble: there IS a Dirty event, as well as a Dirty property - but Bob's right
that:


So you would not need any code in the Form's Dirty event.
--

             John W. Vinson [MVP]
 Microsoft's replacements for these newsgroups:
 http://social.msdn.microsoft.com/Forums/en-US/accessdev/
 http://social.answers.microsoft.com/Forums/en-US/addbuz/
 and see alsohttp://www.utteraccess.com

Thank you all very much..I think the light now dawns over Marblehead!

Best

John Baker
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top