472,780 Members | 4,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 software developers and data experts.

Dates: Using a query result in another query

I have a query:

SELECT tblCalendar.CalendarDay AS LastSunday
FROM tblCalendar
WHERE (((tblCalendar.CalendarDay)>=(Now()-7) And (tblCalendar.CalendarDay)
<DateAdd("d",8-Weekday((Now()-7),2),(Now()-7))) AND ((tblCalendar.Weekday)=1))
;

tblCalendar is a table of consecutive dates from 1998 thru 2020. It has
proven useful in many applications. CalendarDay is the date. The code above
returns the date of the Sunday preceding the day on which the query is run,
based on the system date. I had hoped to use this value in place of a prompt,
[Current WE Date], in an expression in a query field that looks like this:

IIf([Current WE Date]>=[Week Ending]![Week-end Date] And [Week Ending2]![Week-
end Date2] Is Null,"Not Yet Released RED","Planned Not Yet Released")

This query looks to another calendar table ([Week Ending]) which I would
dearly love to retire. This table has a field of consecutive dates and a
field of corresponding WE dates for each date. It is joined by the
consecutive date field in a query to a date field in a data table and the
corresponding WE date is determined from that.

Dates always confound me anyway, but can anyone see anyway I can use
LastSunday in place of the prompt? I already tried just replacing the prompt
with the LastSunday field, but I suspect there's a problem with the join.

There ought to be some way to replace a prompt for the date with the very
date the prompt is looking for as delivered by my LastSunday query, but I'll
be damned if I can figure it out!
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200507/1
Nov 13 '05 #1
6 2394
You shouldn't need the table to get the date of the previous Sunday.

This will give you today's date if today is Sunday or the date of the
previous Sunday for any other day of the week using the current date from
the computer's clock.

Date() - Weekday(Date()) + 1

--
Wayne Morgan
MS Access MVP
"Bill R via AccessMonster.com" <fo***@AccessMonster.com> wrote in message
news:51***********@AccessMonster.com...
I have a query:

SELECT tblCalendar.CalendarDay AS LastSunday
FROM tblCalendar
WHERE (((tblCalendar.CalendarDay)>=(Now()-7) And (tblCalendar.CalendarDay)
<DateAdd("d",8-Weekday((Now()-7),2),(Now()-7))) AND
((tblCalendar.Weekday)=1))
;

tblCalendar is a table of consecutive dates from 1998 thru 2020. It has
proven useful in many applications. CalendarDay is the date. The code
above
returns the date of the Sunday preceding the day on which the query is
run,
based on the system date. I had hoped to use this value in place of a
prompt,
[Current WE Date], in an expression in a query field that looks like this:

IIf([Current WE Date]>=[Week Ending]![Week-end Date] And [Week
Ending2]![Week-
end Date2] Is Null,"Not Yet Released RED","Planned Not Yet Released")

This query looks to another calendar table ([Week Ending]) which I would
dearly love to retire. This table has a field of consecutive dates and a
field of corresponding WE dates for each date. It is joined by the
consecutive date field in a query to a date field in a data table and the
corresponding WE date is determined from that.

Dates always confound me anyway, but can anyone see anyway I can use
LastSunday in place of the prompt? I already tried just replacing the
prompt
with the LastSunday field, but I suspect there's a problem with the join.

There ought to be some way to replace a prompt for the date with the very
date the prompt is looking for as delivered by my LastSunday query, but
I'll
be damned if I can figure it out!
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200507/1

Nov 13 '05 #2
Wayne,

Oooh! That's nifty! That's why you get the big bucks!

Bill

Wayne Morgan wrote:
You shouldn't need the table to get the date of the previous Sunday.

This will give you today's date if today is Sunday or the date of the
previous Sunday for any other day of the week using the current date from
the computer's clock.

Date() - Weekday(Date()) + 1
I have a query:

[quoted text clipped - 33 lines]
I'll
be damned if I can figure it out!

--
Message posted via http://www.accessmonster.com
Nov 13 '05 #3
you could refer to a function in your query which will return the next
friday from the date passed, or the current date if a friday is
entered.

function getWeekend(ByVal dt as Date)
Dim returnDt as date
returnDt = dt

Do While not weekday(returnDt) = 4
returnDt = returnDt + 1
loop

getWeekend = returnDt
end function

if you have a lot of records this may slow your query down - generally
it's not good to call functions from queries, but sometimes there is no
getting around it :s
Also this will run into problems where the weekend falls on thursday -
bank hols etc. But it's the best solution i can think of - but then
thats not saying much!

Nov 13 '05 #4
just re-read your problem, you are looking for the previous sunday! ok,
use

while not weekday(returnDt) = 0
returnDT = returnDT - 1
loop

Nov 13 '05 #5
Thanks Bill,

I was just running into a problem trying to use the same functions to return
next Friday for some of the historic dates in the dataset. They used to use
the following Friday as the WE date, now they use the following Sunday, and I
can't come up with an integer to add to Date()-Weekday(Date()) to come up
with the next Friday (sometimes it requires a 13, sometimes a 5). So it looks
like I'll be using your function.

There'll be an extra 5$ in your pay envelope this week as well ;-)

Bill

BillCo wrote:
you could refer to a function in your query which will return the next
friday from the date passed, or the current date if a friday is
entered.

function getWeekend(ByVal dt as Date)
Dim returnDt as date
returnDt = dt

Do While not weekday(returnDt) = 4
returnDt = returnDt + 1
loop

getWeekend = returnDt
end function

if you have a lot of records this may slow your query down - generally
it's not good to call functions from queries, but sometimes there is no
getting around it :s
Also this will run into problems where the weekend falls on thursday -
bank hols etc. But it's the best solution i can think of - but then
thats not saying much!

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200507/1
Nov 13 '05 #6

Wayne Morgan wrote:
You shouldn't need the table to get the date of the previous Sunday.

This will give you today's date if today is Sunday or the date of the
previous Sunday for any other day of the week using the current date from
the computer's clock.

Date() - Weekday(Date()) + 1

--
Wayne Morgan
MS Access MVP


Very Nice. I'm going to try:

Date() + (8 - Weekday(Date())) Mod 7

for today's date if today is Sunday or the next Sunday for any other
day of the week.

James A. Fortune

Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below....
2
by: wireless200 | last post by:
I've got a table with some datetime fields in it. One field (call it field 1) is of the form mm/dd/yyyy and the other two (fields 2 and 3) are in the form of hh:mm:ss:xx where xx is hundreths of...
3
by: David | last post by:
I'm new to DB2 and I need to write a query that will allow me to find specific dates instead of me having a date range asked for, I want it to be calculated. I've done this in Access by coding...
5
by: Mal | last post by:
Hello. I have a database that tracks reservations at a campground. I want to be able to make a calendar type report that shows how many people are here in given period. Stored for each...
24
by: clare at snyder.on.ca | last post by:
I have a SQL query I need to design to select name and email addresses for policies that are due and not renewed in a given time period. The problem is, the database keeps the information for every...
1
by: yk | last post by:
I am setting up a simple hotel reservation application which have two dates, i.e. CheckIn and CheckOut. I would like to construct a graph based on a crosstab query. Therefore, I need to have...
2
by: ameshkin | last post by:
Hi GUys, Im trying to compare two dates in MYSQL. But its not treating the dates as numbers, but as strings. I try using strtotime but that did not work. Basically, if the last comment is...
14
by: Frederik Vanderhaeghe | last post by:
Hi, I have made a search page on which users can search for documents. They can search by documentnumber, customername,... and also by date. Now the problem is that when a date is entered it...
2
by: joeybarbecho | last post by:
hello... I have a program that saves dates. Problem: Given: sample table: Leave ------------------------------------------ ID | UserID | DateFrom | DateTo|...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.