code that evaluates a control source

suemack

New member
Local time
Today, 00:08
Joined
Apr 7, 2003
Messages
9
I have a form with a txt box called length_stay whose control source is:
=DateDiff("d",[DOA],[DOD])+1
where DOA and DOD refer to date fields on the form.
this part works fine.
now, if the number that is returned is <=3 then I want another field on this form called LBPATH to =7.

I went to the AfterUpdate Event and said:

If length_stay <=3 then
LBPATH = 7
end if

but this doesn't work... I also tried the BeforeUpdate.. no luck.
 
suemack,

I think you're pretty close here. I didn't try to replicate this
but your field is not firing the Before or After Update events
because it is not being "updated".

You might try the OnCurrent event of the form.

Wayne
 
thanks

thanks for the reply. The OnCurrent didn't work but it immediately opened my eyes to the fact that I really need to lean more about the different events so that I can figure out where to put certain peices of code..
I actually needed the LBPATH on a different form so I moved it and then changed the code a bit which enabled me to use the OnLoad event to make things work... !

thanks for the eye opener!

(This is a great site)!!
 
Another way to deal with this (when the fields are on the same form) is to make the control source equal to a function.

This will require adding Me.Recalc to the afterupdate events of the [DOA] and [DOD] fields.

Control Source
=fLength([DOA],[DOD])

Code:
'Code in the Class module of the form

Private Function fLength(DOA as Date, DOD as Date) as Integer

fLenght=DateDiff("d",DOA,DOD)+1 

If fLength <=3 then 
  Me.LBPATH = 7 
end if
 

Users who are viewing this thread

Back
Top Bottom