Patrick O'Dea
asked on
VBA Generic Way to address a field
All,
I am writing an audit trail for changes to tables etc (I know - reinventing the wheel. But at least its my wheel).
Take a table with 50 fields.
I want to do a comparison in each beforeupdate event such as ..
... If field1.oldvalue <> field1.value then ...
I am trying to minimise the code for obvious reasons.
Rather than repeat this above "IF" code I was wondering if it was possible to somehow just call a function that simple refers to the "current field".
In order words, I do not want to specify field names - I want the system to know that "current field" means the field that the "event" started from.
So if I was in field 25 and used a "BeforeUpdate" event - the system would know that "current field" meant field 25.
Is there such a facility??
Is this clear??
I am writing an audit trail for changes to tables etc (I know - reinventing the wheel. But at least its my wheel).
Take a table with 50 fields.
I want to do a comparison in each beforeupdate event such as ..
... If field1.oldvalue <> field1.value then ...
I am trying to minimise the code for obvious reasons.
Rather than repeat this above "IF" code I was wondering if it was possible to somehow just call a function that simple refers to the "current field".
In order words, I do not want to specify field names - I want the system to know that "current field" means the field that the "event" started from.
So if I was in field 25 and used a "BeforeUpdate" event - the system would know that "current field" meant field 25.
Is there such a facility??
Is this clear??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Me will give you the field name if the event handler pertains to a field. Me refers to the active object, which will be the form if no control in the form is selected
If you do a debug.print me.name within the beforeupdate or event handler, you should see the field name
If you do a debug.print me.name within the beforeupdate or event handler, you should see the field name
ASKER
reb73,
See simple frm1 attach.
Amend the "name1" field on frm1.
The formname will then be displayed (not the field name).
AM I missing something??
Database4.zip
See simple frm1 attach.
Amend the "name1" field on frm1.
The formname will then be displayed (not the field name).
AM I missing something??
Database4.zip
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
forgot to mention, you would want to do this on the form_beforeudpate event, and not the field_beforeupdate.
-RK
-RK
here is your example with this implemented. Please note that the form_update event takes place when you save the record (including going to a different record)
Database4-v2.zip
Database4-v2.zip
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks you all!
ASKER
That's close ..
Me.Name gives me the formname.
How do I get the name of the individual field?