Code field to change if needed

  • Thread starter Thread starter Stockwell43
  • Start date Start date
S

Stockwell43

Hello,

I have a Start Date, End Date and a third field called Wait Time. Currently
it is set up so that it excludes weekends which is fine. However, if there is
a holiday, I just want the user to change the Wait Time to subtract one day.
I have code in the control source of the wait time field so it will not allow
the field to be changed. Is there a way to make it work like it does but put
the code somewhere else so the field can be changed?


Thank you!!!
 
Put it in the form current event, but be sure to exclude new records. Now,
when you start entering a new record, you will still want it to calculate the
wait time. To do that, write a function that does the calculation. Call the
function from the current event and the After Update event of start time and
end time. You will need to account for Nulls. Here is an example

Private Function CalcWaitTime() As Variant

If IsNull(Me.StartTime) Or IsNull(Me.EndTime) Then
CalcWaitTime = Null
Else
'Do your calculation here
End If

Now another idea. If you had a Holiday table, you could subtract any
holidays in the time with DCount on the table:

WaitTime = WaitTime - DCount("*","tblHoliday","[StartTime] >= #" &
Me.StartTime & "# And [EndTime] <= #" & Me.EndTime & "#")
 
Back
Top