473,480 Members | 2,157 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Overlapping Date Periods

5 New Member
I have an Access table listing cabin numbers, arrival dates, and depart dates. I need to select all cabins (and their dates) having either an arrival date or a depart date within a specified week, or having both dates outside the specified week. I need to open a report using these criteria.
Placing those criteria in a query design grid produces a message that they are too complicated. I tried a recordset approach but I am not adept in that area.

I would appreciate any help on this
Oct 31 '06 #1
6 2511
PEB
1,418 Recognized Expert Top Contributor
Hi,

So you need to convert your arrivel and depart dates to weeks

Use the function datepart("ww", [ArrivalDate]) to obtain the week

the same for your depart date

put those functions in a separate column in your query and in the criteria part put the respectiv criteria about!

Nice luck!
:)
Oct 31 '06 #2
NeoPa
32,556 Recognized Expert Moderator MVP
Alternatively, if you post the criteria you used I can check it over and make recommendations.
Oct 31 '06 #3
George1029
5 New Member
Alternatively, if you post the criteria you used I can check it over and make recommendations.
Here is the code based on the PEB recommendation. It is a function because it is called from the switchboard. When it runs, all the variables are correct, but no data results where some should.
Public Function Occupancy()
Dim EnterDate As Date
Dim MyWeek As Integer
Dim MyYear As Integer
Dim MyCriteria As String

EnterDate = InputBox("Please enter a date.")
MyWeek = DatePart("ww", EnterDate)
MyYear = DatePart("yyyy", EnterDate)
MyCriteria = "([ArrWk] = ' " & MyWeek & " ' OR [DepartWk] = ' " & MyWeek & " ' " & _
"OR ([ArrWk]<' " & MyWeek & " ' and [DepartWk] > ' " & MyWeek & " ')) " & _
"AND ([ArrYear] = ' " & MyYear & " ')"

Dim MyRpt As String
MyRpt = "rptCabinOccupancy"

DoCmd.OpenReport MyRpt, acViewPreview, "qryWeekSum_01", MyCriteria

End Function

Thank you for your assitance
Oct 31 '06 #4
NeoPa
32,556 Recognized Expert Moderator MVP
I'm thinking your criteria are still the problem here. I'll just go through the code of this, rather than the logic.
Your Code
Expand|Select|Wrap|Line Numbers
  1. MyCriteria = "([ArrWk] = ' " & MyWeek & " ' OR [DepartWk] = ' " & MyWeek & " ' " & _
  2. "OR ([ArrWk]<' " & MyWeek & " ' and [DepartWk] > ' " & MyWeek & " ')) " & _
  3. "AND ([ArrYear] = ' " & MyYear & " ')"
This has spaces inside the eventually resolved strings.
([ArrWk] = 'SPACEvalueSPACE'... which should never work. White space (spaces; tabs; new lines; etc) are fine in the SQL code except when they appear in strings.
Try :-
Expand|Select|Wrap|Line Numbers
  1. MyCriteria = "([ArrWk] = '" & MyWeek & "' OR [DepartWk] = '" & MyWeek & "' " & _
  2. "OR ([ArrWk]<'" & MyWeek & "' and [DepartWk] > '" & MyWeek & "')) " & _
  3. "AND ([ArrYear] = '" & MyYear & "')"
Oct 31 '06 #5
MMcCarthy
14,534 Recognized Expert Moderator MVP
Firstly, the user entering a date is entered as a string and has to be converted to a date.

Next MyWeek is an integer and doesn't require single quotes as they are only needed for strings.

Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Function Occupancy()
  3. Dim EnterDate As Date
  4. Dim MyWeek As Integer
  5. Dim MyYear As Integer
  6. Dim MyCriteria As String
  7.  
  8. EnterDate = CDate(InputBox("Please enter a date:"))
  9. MyWeek = DatePart("ww", EnterDate)
  10. MyYear = DatePart("yyyy", EnterDate)
  11. MyCriteria = "([ArrWk]=" & MyWeek & " OR [DepartWk]=" & MyWeek & ")" & _
  12. " OR ([ArrWk]<" & MyWeek & " and [DepartWk]>" & MyWeek & ")" & _
  13. " AND [ArrYear]=" & MyYear & ")"
  14.  
  15. Dim MyRpt As String
  16. MyRpt = "rptCabinOccupancy"
  17.  
  18. DoCmd.OpenReport MyRpt, acViewPreview, "qryWeekSum_01", MyCriteria
  19.  
  20. End Function
  21.  
  22.  
Nov 1 '06 #6
George1029
5 New Member
Many thanks to all for the assistance. Here is how I finally solved it
[code]
Public Function Occupancy()
On Error GoTo Err_Occupancy
Dim EnterDate As Date
Dim MyWeek As Integer
Dim MyYear As Integer
Dim MyCriteria As String
Dim MyOne As String, MyTwo As String, MyThree As String, MyFour As String, MyFive As String

EnterDate = InputBox("Please enter a date.")
MyWeek = DatePart("ww", EnterDate)
MyYear = DatePart("yyyy", EnterDate)
MyOne = "[ArrWk] = " & MyWeek
MyTwo = "[DepartWk] = " & MyWeek
MyThree = "[ArrWk] < " & MyWeek
MyFour = "[DepartWk] > " & MyWeek
MyFive = "[ArrYear] = " & MyYear

MyCriteria = MyFive & "AND(" & MyOne & "OR" & MyTwo & "OR(" & MyThree & "And" & MyFour & "))"

Dim MyRpt As String
Dim MyFilter As String

MyRpt = "rptCabinOccupancy"
MyFilter = "qryWeekSum_01"
DoCmd.OpenReport MyRpt, acViewPreview, MyFilter, MyCriteria

Exit_Occupancy:
Exit Function

Err_Occupancy:
MsgBox Err.Description
Resume Exit_Occupancy

End Function

[End of code]
That's the end of the code. This is the only way I could figure out the syntax.
Thanks again


[quote=mmccarthy]Firstly, the user entering a date is entered as a string and has to be converted to a date.

Next MyWeek is an integer and doesn't require single quotes as they are only needed for strings.

Try this:

[code]

Public Function Occupancy()
Dim EnterDate As Date
Dim MyWeek As Integer
Dim MyYear As Integer
Dim MyCriteria As String

EnterDate = CDate(InputBox("Please enter a date:"))
MyWeek = DatePart("ww", EnterDate)
MyYear = DatePart("yyyy", EnterDate)
MyCriteria = "([ArrWk]=" & MyWeek & " OR [DepartWk]=" & MyWeek & ")" & _
" OR ([ArrWk]<" & MyWeek & " and [DepartWk]>" & MyWeek & ")" & _
" AND [ArrYear]=" & MyYear & ")"

Dim MyRpt As String
MyRpt = "rptCabinOccupancy"

DoCmd.OpenReport MyRpt, acViewPreview, "qryWeekSum_01", MyCriteria

End Function
Nov 1 '06 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3197
by: Graeme Longman | last post by:
Hi everyone, I was wondering if anyone has written some Python code which uses a start date and end date and a given interval (day, month or year) and outputs all the time periods for that range...
3
12779
by: Phil Sandler | last post by:
All, I have a table with start and end dates/times in it, and would like to be able to calculate the number of hours represented, accounting for overlapping records. Note that I am looking...
7
1737
by: LineVoltageHalogen | last post by:
Greetings All, I was hoping that someone might be able to help me with the following issue: table ddl: create table exchange ( exchangefrom varchar(6), exchangeto varchar(6),...
5
3447
by: jnikle | last post by:
I have two completely unrelated tables, one for reviews and another for pay periods. The reviews table has a review date in it, and the pay periods table is just a list of the beginnings of pay...
4
4700
by: gzaxar | last post by:
Hi to all in forum. It is my first post here. I am quite new in MsAccess programming. Here is a problem which i am facing to. I want to keep records of employees CV's. More specifically i want...
1
1404
by: lyntonS | last post by:
I need to create a Summary Report which shows the current 6 month periods values, in addition to the perious 6 months periods? Currently I have two separate queries. One I have built using...
10
2365
by: kyosohma | last post by:
Hi, I am working on a timesheet application in which I need to to find the first pay period in a month that is entirely contained in that month to calculate vacation time. Below are some example...
2
3828
by: monadel | last post by:
I have a problem with checking the overlapping date. Basically I am developing a database using MS Access (VB scripts) and SQL queries. I have 2 tables which are empTable and empLeaveTable. In a...
1
1726
by: guilhermelemmi | last post by:
I'm creating a function that will take a start date, a period duration (in months)and a maximum date, and will calculate the periods start and end dates until reaching the maximum date. For...
0
6920
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7022
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5365
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4501
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3004
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
572
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.