PC Review


Reply
Thread Tools Rate Thread

Calculate weekending date from any day

 
 
=?Utf-8?B?bWdrYWFt?=
Guest
Posts: n/a
 
      23rd Jan 2007
I have a table and the primay key is the weekending date field. I need a
default value on this field so that I can have the employee's enter in
information from any day and the weekending date would than return the
saturday date. Can I do this as a default Value calculations in the table?

Thanks in advance!

 
Reply With Quote
 
 
 
 
Ken Snell \(MVP\)
Guest
Posts: n/a
 
      23rd Jan 2007
This function can be used to do what you seek; put it in a regular module:

' start of code
Public Function DateOfSpecificWeekDay(ByVal OriginalDate As Date, _
ByVal intWeekDay As Integer) As Date
' ** THIS FUNCTION RETURNS THE DATE OF THE SPECIFIC DAY OF THE WEEK
' ** IN WHICH THE ORIGINAL DATE IS.
' ** intWeekDay = 1 is Sunday, 2 is Monday, etc.

On Error Resume Next

DateOfSpecificWeekDay = DateAdd("d", -DatePart("w", OriginalDate, _
1) + intWeekDay, OriginalDate)
Err.Clear
End Function
' end of code


Then, the Saturday date for the week containing today's date would be
SaturdayDate = DateOfSpecificWeekDay(Date(), 7)

--

Ken Snell
<MS ACCESS MVP>

"mgkaam" <(E-Mail Removed)> wrote in message
news:819285A4-86FB-4574-82B1-(E-Mail Removed)...
>I have a table and the primay key is the weekending date field. I need a
> default value on this field so that I can have the employee's enter in
> information from any day and the weekending date would than return the
> saturday date. Can I do this as a default Value calculations in the
> table?
>
> Thanks in advance!
>



 
Reply With Quote
 
=?Utf-8?B?bWdrYWFt?=
Guest
Posts: n/a
 
      23rd Jan 2007
Thanks for the reply, now I am still new to access, how would I connect this
to my weekending field on a table or form? I need the weekending to show up
on a new form each week.

Thanks again in advance.


"Ken Snell (MVP)" wrote:

> This function can be used to do what you seek; put it in a regular module:
>
> ' start of code
> Public Function DateOfSpecificWeekDay(ByVal OriginalDate As Date, _
> ByVal intWeekDay As Integer) As Date
> ' ** THIS FUNCTION RETURNS THE DATE OF THE SPECIFIC DAY OF THE WEEK
> ' ** IN WHICH THE ORIGINAL DATE IS.
> ' ** intWeekDay = 1 is Sunday, 2 is Monday, etc.
>
> On Error Resume Next
>
> DateOfSpecificWeekDay = DateAdd("d", -DatePart("w", OriginalDate, _
> 1) + intWeekDay, OriginalDate)
> Err.Clear
> End Function
> ' end of code
>
>
> Then, the Saturday date for the week containing today's date would be
> SaturdayDate = DateOfSpecificWeekDay(Date(), 7)
>
> --
>
> Ken Snell
> <MS ACCESS MVP>
>
> "mgkaam" <(E-Mail Removed)> wrote in message
> news:819285A4-86FB-4574-82B1-(E-Mail Removed)...
> >I have a table and the primay key is the weekending date field. I need a
> > default value on this field so that I can have the employee's enter in
> > information from any day and the weekending date would than return the
> > saturday date. Can I do this as a default Value calculations in the
> > table?
> >
> > Thanks in advance!
> >

>
>
>

 
Reply With Quote
 
=?Utf-8?B?TXIgQg==?=
Guest
Posts: n/a
 
      23rd Jan 2007
Here is another way to do what you want:

Place the following in the "Default Value" property of the Weekending field:

=DateAdd("d",7-Weekday(Date()),Date())

This will always place the date of the next Saturday.
--
HTH

Mr B


"mgkaam" wrote:

> I have a table and the primay key is the weekending date field. I need a
> default value on this field so that I can have the employee's enter in
> information from any day and the weekending date would than return the
> saturday date. Can I do this as a default Value calculations in the table?
>
> Thanks in advance!
>

 
Reply With Quote
 
=?Utf-8?B?RHVhbmUgSG9va29t?=
Guest
Posts: n/a
 
      23rd Jan 2007
Your date could be any one of 52 (or so) values each year. I'm not sure how
you could set a default value in this table. You could set the default value
to:
=DateAdd("d",-Weekday(Date())+7,Date())
which would default to the Saturday of the current week. I would probably
set the default in the control on your form used for data entry.
--
Duane Hookom
Microsoft Access MVP


"mgkaam" wrote:

> I have a table and the primay key is the weekending date field. I need a
> default value on this field so that I can have the employee's enter in
> information from any day and the weekending date would than return the
> saturday date. Can I do this as a default Value calculations in the table?
>
> Thanks in advance!
>

 
Reply With Quote
 
=?Utf-8?B?bWdrYWFt?=
Guest
Posts: n/a
 
      23rd Jan 2007
Everyone thank you for helping! They both worked! Now just one more
question. If I make this into a single data entry form with just that weeks
totals, when I start a new week it should be with the new weekend date and
not change the previous records to the current date right, because I set up
the primary key to be for that week's ending date right? Does the weekending
date than change to the new weekending once monday starts?



"Duane Hookom" wrote:

> Your date could be any one of 52 (or so) values each year. I'm not sure how
> you could set a default value in this table. You could set the default value
> to:
> =DateAdd("d",-Weekday(Date())+7,Date())
> which would default to the Saturday of the current week. I would probably
> set the default in the control on your form used for data entry.
> --
> Duane Hookom
> Microsoft Access MVP
>
>
> "mgkaam" wrote:
>
> > I have a table and the primay key is the weekending date field. I need a
> > default value on this field so that I can have the employee's enter in
> > information from any day and the weekending date would than return the
> > saturday date. Can I do this as a default Value calculations in the table?
> >
> > Thanks in advance!
> >

 
Reply With Quote
 
=?Utf-8?B?RHVhbmUgSG9va29t?=
Guest
Posts: n/a
 
      23rd Jan 2007
If you use the expression that I suggested, the new/default date will be the
Saturday of the current week. If this isn't what you want, you need to tell
us what week ending date you need.

--
Duane Hookom
Microsoft Access MVP


"mgkaam" wrote:

> Everyone thank you for helping! They both worked! Now just one more
> question. If I make this into a single data entry form with just that weeks
> totals, when I start a new week it should be with the new weekend date and
> not change the previous records to the current date right, because I set up
> the primary key to be for that week's ending date right? Does the weekending
> date than change to the new weekending once monday starts?
>
>
>
> "Duane Hookom" wrote:
>
> > Your date could be any one of 52 (or so) values each year. I'm not sure how
> > you could set a default value in this table. You could set the default value
> > to:
> > =DateAdd("d",-Weekday(Date())+7,Date())
> > which would default to the Saturday of the current week. I would probably
> > set the default in the control on your form used for data entry.
> > --
> > Duane Hookom
> > Microsoft Access MVP
> >
> >
> > "mgkaam" wrote:
> >
> > > I have a table and the primay key is the weekending date field. I need a
> > > default value on this field so that I can have the employee's enter in
> > > information from any day and the weekending date would than return the
> > > saturday date. Can I do this as a default Value calculations in the table?
> > >
> > > Thanks in advance!
> > >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rounding Dates to Weekending Date Neil Pearce Microsoft Excel Misc 2 2nd Sep 2009 04:24 PM
Display a weekending date even if there is no data CCripe Microsoft Access Reports 5 4th Mar 2009 04:16 PM
Weekending date issue =?Utf-8?B?bWdrYWFt?= Microsoft Excel Misc 1 31st Jan 2007 06:46 AM
calculating weekending date =?Utf-8?B?RElZ?= Microsoft Access 4 6th Sep 2006 01:04 PM
Get Date today from WeekEnding Jako Microsoft Excel Programming 3 26th Jul 2004 01:47 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:42 PM.