Here's how I would go about it. I can use the optional parameter of the
Weekday function or just lay out what I want:
I'd like to format something like:
DateAdd("d", SomeNumber, [DateField])
To get SomeNumber:
Weekday, SomeNumber
2 => 0
3 => -1
4 => -2
5 => -3
6 => -4
7 => -5
1 => -6
SomeNumber = -(X + 5) Mod 7 works. After checking that Access doesn't
do anything unexpected with the Mod function (it doesn't):
=Format(DateAdd("d", -(Weekday([DateField]) + 5) Mod 7, [DateField]),
"mm/dd/yy")
should do it. I used a different name for the date field since Date is
a reserved word in Access. Just replace DateField in both places with
the new name you are using.
James A. Fortune
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
Then use it as the Control Source in the textbox to show you the desired
date:
=DateOfSpecificWeekDay(Date(), 2)
Or you could just use this expression as the Control Source of your textbox:
= DateAdd("d", -DatePart("w", Date(), 1) + 2, Date())
--
Ken Snell
<MS ACCESS MVP>
"Dan" <D...@discussions.microsoft.com> wrote in message
news:79D0A0B6-5FC6-4BF7...@microsoft.com...
is there a way to manipulate the above query to allow me to have excel link
to it properly ?
TheWeekDayNumber: DateAdd("d", -DatePart("w", [DateFieldName], 1) + 1,
[DateFieldName])
--
Ken Snell
<MS ACCESS MVP>
"Aaron" <Aa...@discussions.microsoft.com> wrote in message
news:038D0FC9-1551-4086...@microsoft.com...
? date() - weekday(date()) + 1
8/5/2007
Bob
Ken Snell (MVP) wrote:
>I've not worked with MSQuery, so I cannot give a firm answer. However, you
>could replace the function call in the query with the entire expression that
>is used in the function (I'm assuming that you want to use Sunday as the
>first day of the week, so I put a 1 in for the intWeekDay value in the
>expression):
>
>TheWeekDayNumber: DateAdd("d", -DatePart("w", [DateFieldName], 1) + 1,
>[DateFieldName])
>
>> This function works wonderfully! What I'm trying to do next is to have an
>> excel sheet linked to my query containing the above formula. However, the
>[quoted text clipped - 38 lines]
>>> > > line in
>>> > > the Date Fotter section? Thx.
--
Message posted via http://www.accessmonster.com
Can you give us the actual SQL statement of the ACCESS query, and the exact
steps that you used to link to the query in EXCEL?
--
Ken Snell
<MS ACCESS MVP>
"Aaron" <Aa...@discussions.microsoft.com> wrote in message
news:29429737-D60A-4747...@microsoft.com...
after I put in an if statement to catch this, it works like a charm.
Thanks much Ken
Yes, that indeed will cause that error < smile >.
>
> after I put in an if statement to catch this, it works like a charm.
Good work!
>
> Thanks much Ken
You're welcome.