Defaulting a Date

R

Raj

I am creating a database to track employees time. What I would like to do is
have the [Period End Date] set to default automatically to the last Saturday
of the period. Example after the end of the current pay period 11/27/04 the
date will default to 12/11/04.
 
A

Alexandr Artamonov

Raj, I can see that your posting is being ignored just as mine is.
I'm not a professional developer but I tried to find a solution to your
problem.
First, your question is not quite correct IMHO. "Defaulting" means a
pre-inserted value in a new record. As there's no data yet in a new record
(period end) the last Saturday can't be calculated. But there's possible to
calculate the last Saturday for existing records. Once you've calculated it
you can do whatever you wish with it - e.g. insert into a record.

I wrote a function returning the last Saturday before a date. It has no
errer handler - so it has to be improved. Once you put it in a general
module you can use it in a query or a calculated field on a form. Please
consider it just as a hint - it only uses one argument - the end date. If
you want to use two arguments you should modify it. Good luck!

Public Function MySat(N As Date)
'finds the next Saturday less or equal to the argument
If Weekday(N, vbMonday) = 6 Then
MySat = N
Else
MySat = MySat(N - 1)
End If

End Function

To test the function:

Private Sub TryMySat()
Dim X As Date
X = InputBox("enter date")

MsgBox (MySat(X))

End Sub
 

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