Date calculation procedure not passing value to default value property

G

Guest

I've written a procedure to calculate a date that is seven days from today that excludes weekends. I've created it as standard module that should be available to all parts of the database. However, when I call the procedure from the default value property of a text box on a form it returns either nothing or #?Name error. I've even tried creating a macro and using the RunCode function to run the script as well as placing the code within the form module and using an event procedure to call the code. I've debugged the code and it works fine. The field is a date format and the procedure should return a date that is seven days from the current date excluding weekends. I'm sure it's something obvious but I'm in the forest looking for trees aparantly. Code is as follows

Function DateCalc() As Dat

Dim dtDate As Dat

dtDate = Now() +
If Weekday(dtDate) = 7 The
dtDate = dtDate +
ElseIf Weekday(dtDate) = 1 The
dtDate = dtDate +
End I

dtDate = Format(dtDate, "mm/dd/yyyy"

DateCalc = dtDat

End Functio

Any assistance would be appreciated.
 
R

Rod Scoullar

Terry,

Try putting the function call in the Form_Current event, ie txtDateMinus7 =
DateCalc().

If you don't want an existing value to change then use If Not
IsNull(txtDateMinus7) thentxtDateMinus7 = DateCalc()

Rod Scoullar.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top