Best event to check field content

InstructionWhich7142

Registered User.
Local time
Today, 19:20
Joined
Feb 24, 2010
Messages
206
I have a form with a number of fields and sections which change visibility based on the data entered in other fields,

The fields have an "on update" event to check the content of the field and make the appropriate changes,

I've changed this form to be able to edit records instead of "Data Entry" so now I need the checks to occur when the record changes as well as when data is entered,

How best can I achieve this without simply duplicating the code (which seems like a bad idea) into the "On Current" event?
 
Put the code in a separate sub or function in the form module then simply call it from your current event and the control update event (presumable after update)
 
Doy!

In the past I have ended up making a sub/function in a regular module which I always felt was a faff as you can't use "me.object" etc

For some reason it never even crossed my mind I could just make a custom function in the form module :)

Thanks
 
you can't use "me.object" etc
You can, by passing the form as a parameter e.g.

Code:
public function setctrls(frm as Form) as boolean
dim ctrl as control
 
on error goto errctrl
 
for each ctrl in frm.ctrl
   if ctrl.type=actextbox then ctrl.backcolor=vbred
next
setctrls=true
exit function
 
errctrl:
    setctrls=false
 
end function

and to call it from your form you would use something like

Code:
setctrls me
 
or
 
setctrls mysubformctrl.form
 
or
 
if setctrls(me) then
    ...do something...
else
    ...do something else....
end if
 

Users who are viewing this thread

Back
Top Bottom