Run Function on any data change in a Form?

  • Thread starter Thread starter HumanJHawkins
  • Start date Start date
H

HumanJHawkins

I have a .adp connected to SQL. The visibility of some of the fields should
be dependant on the data from other fields.

So, I want to run a function like the following every time the user changes
anything:
Function UpdateDisplay()
If vchFactType = "multiple" Then
iMultipleLimit.Visible = True
Else
iMultipleLimit.Visible = False
End If
End Function

I have tried the "Private Sub Form_SelectionChange()" function, but it
doesn't seem to trigger the function when my selection on the form actually
changes.

What is the standard way of doing this?

I also want to run the same function when the user goes from one record to
the next... I can't seem to find how to do this either.

Thanks in advance for any help.
 
Controls on bound forms have a Dirty event that fires the first time the
control is changed per record and a Change event that fires with each change
of the control. There are also KeyPress, KeyUp, and KeyDown events. Similar
events occur on the form with the addition of the Current event that fires
upon reaching a new record. There are also Before and After Update events
for both controls and forms. In fact, Access has more data connected events
than any other DBMS including all other languages.

Open the property sheet, and click on the Event tab, then click in each of
the events and press F1. The help files will tell you what most of them do.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
I think your tips about "the Current event" and the before and after update
events are on the right track. These at least will help. But I am really
looking for a way to handle this at the form level as the user changes
things. I.e. To make it update in real time without adding an "On Change"
type handler for every control on the page.

The goal is not just laziness... I think it would be a lot cleaner and have
less maintenance and debugging as the thing is developed. Is there no event
that fires when any control on a form has been changed?

Thanks!
 
Create a function and use the following syntaxe for the relevant control
event property:

=MyFunction()

This will be easy to duplicate for each necessary events by using Ctrl-C or
by using a small piece of code that will modify automatically all the
controls on the form.

You can also setup a macro that will call your function and use it instead.

S. L.
 
Back
Top