arunprathiba
11-09-2007, 12:43 PM
Hi All,
i am new to MS Access.
I am creating a database, in the table i want a field to automatically generate date.
Eg: If start date is todays date, the end date should be 14 business days after the start date. Is it feasible.
Plz do help me.
thanks
Arun
raskew
11-09-2007, 01:18 PM
Hi -
Try copying the following to a standard module then testing as shown. Note that business days in this example are Monday - Friday. If you're using other days, please post back.
Function UpBusDays3(pstart As Date, _
pnum As Integer, _
Optional pAdd As Boolean = True) As Date
'*******************************************
'Purpose: Add or subtract business days
' from a date
'Coded by: raskew
'Inputs: 1) +) ? UpBusDays3(#2/17/06#, 3, True)
' 2) -) ? UpBusDays3(#2/22/06#, 3, False)
'Output: 1) +) 2/22/06
' 2) -) 2/17/06
'*******************************************
Dim dteHold As Date
Dim i As Integer
Dim n As Integer
dteHold = pstart
n = pnum
For i = 1 To n
If pAdd Then 'add days
dteHold = dteHold + IIf(WeekDay(dteHold) > 5, 9 - WeekDay(dteHold), 1)
Else 'subtract days
dteHold = dteHold - IIf(WeekDay(dteHold) < 3, Choose(WeekDay(dteHold), 2, 3), 1)
End If
Next i
UpBusDays3 = dteHold
End Function
HTH - Bob
arunprathiba
11-15-2007, 08:55 AM
Hi,
Thanks for the reply.
I need to only add 14 business days to the field in the table.
Do i have copy this in the module and assign this upbusdays3 in the criteria row?
Please advice.
Arun
RuralGuy
11-16-2007, 06:54 AM
You need to put Bob's function in a standard module named basFunctions and then in a query of your table add a field and set the field to:
NewField:=UpBusDays3([YourDateField],14,True)