Determine when data on a form has changed

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

As stated in my previous post I'm attempting to move from bound forms to
unbound forms. As a result I need to determine when data on my form has
changed so that I can ask my user whether they want to save their changes.
Now from what I understand, I'm supposed to add a hidden checkbox on my form
with a default value of false. And whenever a field on my form changes I
should have my checkbox value changed to true and then based on my checkbox
value my save function will run.

The part where I am confused, I know this is probably something very simple,
is am I supposed to create an afterupdate event procedure for every field on
my form to set my checkbox value to true? or is there a single public
function that I can write to have it scan through the fields on my form and
determine whether any of the field values have changed? Basically I don't
want to have to type "Flagedited = true" 30 times for each field.

I have another question too. Is there a way to count the amount of records
from the current record up to .bof and then assign that value to a record
number textbox on my form?

Thanks a ton to those who can help me.

Jonathan
 
For your first question, you can write a procedure that will scan each field
of your form on opening and set the property AfterUpdate to a call to a
function; something like:

Public Function SetFlag(v As Variant)

MsgBox "Call to SetFlag(): " & CStr(v)

End Function

Private Sub Form_Open(Cancel As Integer)

Dim i
Dim ctrl As Control

For i = 0 To Me.Controls.Count - 1
Set ctrl = Me.Controls(i)

If (TypeOf ctrl Is TextBox) Then
ctrl.AfterUpdate = "=SetFlag([" & ctrl.name & "].value)"
End If
Next i

End Sub


You can also work in design mode to set this properties definitively.
Search Google for « AllForms acDesign » for more info on that.

For you second question, take a look at Me.Recordset.AbsolutePosition or
Me.RecordsetClone.AbsolutePosition.
 
Hello,
You wrote on Thu, 15 Sep 2005 06:21:10 -0700:

JB> The part where I am confused, I know this is probably something very
JB> simple, is am I supposed to create an afterupdate event procedure for
JB> every field on my form to set my checkbox value to true? or is there a
JB> single public function that I can write to have it scan through the
JB> fields on my form and determine whether any of the field values have
JB> changed? Basically I don't want to have to type "Flagedited = true" 30
JB> times for each field.

there's form property "dirty", as well as property "dirty" for each
control. But that is for bound forms.

JB> I have another question too. Is there a way to count the amount of
JB> records from the current record up to .bof and then assign that value
JB> to a record number textbox on my form?

There's a way Sylvain mentioned, but again, that is for bound forms. If your
form is unbound, it has no recordset and no current record, by definition.

I think that working with bound forms in Access is much more productive. See
discussion at
http://www.experts-exchange.com/Databases/MS_Access/Q_21560591.html . If the
forms are ubound, so you give up 90% of the advantages of Access (to which
point your questions are perfect illustation), then why not to use VB? it's
more powerful.


Vadim Rapp
 
I have to agree with the guy who pointed out that bound forms are much more
productive, but there are occasionally reasons to have unbound forms as well
(for instance, two forms that could have portions of the same record
on-screen at the same time, but you want updates live for both).

So let's take it as a given that you're working with unbound forms for
whatever reason...would it maybe be easier to ReDim an array of variants for
each "wannabe bound" control, then when you move to a new record, fill the
array with the current values for all controls, and when you're about to
leave the record, check all the values against your originals to see if
they've changed?

It avoids a whole bunch of AfterUpdate's.

Anyway, it's a thought.



Rob
 
Back
Top