Grace Hopper had to do some basic admin housekeeping to keep a record of
code and how to call it.
In the room was a Unisys computer to run these programs.
She got the computer to do the work and so invented the compiler.
Lesson if it is boring and repetitive that is just the job for a machine.
The code you are writhing
> EvaluateContentsAndSaveIfChangedOrNewEntry (column, table, timestamp)
"column" can come from ControlSource of a bound control so if
we pass the control to the procedure it can be worked out.
> EvaluateContentsAndSaveIfChangedOrNewEntry (ControlName, table, timestamp)
Table is part of the form RecordSource, so if we copy the relevant value to
the form.tag property we can get it.
> EvaluateContentsAndSaveIfChangedOrNewEntry (ControlName, Me.Tag,
timestamp)
timestamp is easy so we use Now(), which you are probably already using.
By adding a new module to the database window we can write our code.
Sub CreateEventHandlers( frm As Form)
And call it from the immediate debug window "CreateEventHandlers
forms!form1"
So now all we have to do is get access the do the writing part for us.
well first we have to see if the form already has a module using
Me,HasModule if not then create it
Debug.Print frm.Module.Type
' this should print 1 (object module)
If we iterate through the forms controls and only process the ones of
interest.
Sub CreateEventHandlers(frm As Form)
Dim Mdl As Module
Set Mdl = frm.Module
Dim EventProcLine As Long
Dim Ctl As Control
For Each Ctl In frm.Controls
If Ctl.ControlType <> acTextBox Then
' skip
ElseIf Ctl.ControlSource = "" Then
' skip
Else
EventProcLine = frm.Module.CreateEventProc("LostFocus",
Ctl.Name)
Mdl.InsertLines EventProcLine + 1, vbTab & "Call
EvaluateContentsAndSaveIfChangedOrNewEntry(""" & Ctl.Name & """, Me.Tag,
Now())"
End If
Next Ctl
End Sub
Any ideas? John
> Gregorio
>
[quoted text clipped - 40 lines]
> >
> > - Greg