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
6 2520 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!
:)
NeoPa 32,566
Recognized Expert Moderator MVP
Alternatively, if you post the criteria you used I can check it over and make recommendations .
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("Pleas e 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 = "rptCabinOccupa ncy"
DoCmd.OpenRepor t MyRpt, acViewPreview, "qryWeekSum_01" , MyCriteria
End Function
Thank you for your assitance
NeoPa 32,566
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 - MyCriteria = "([ArrWk] = ' " & MyWeek & " ' OR [DepartWk] = ' " & MyWeek & " ' " & _
-
"OR ([ArrWk]<' " & MyWeek & " ' and [DepartWk] > ' " & MyWeek & " ')) " & _
-
"AND ([ArrYear] = ' " & MyYear & " ')"
This has spaces inside the eventually resolved strings.
([ArrWk] = ' SPACEvalue SPACE'... which should never work. White space (spaces; tabs; new lines; etc) are fine in the SQL code except when they appear in strings.
Try :- - MyCriteria = "([ArrWk] = '" & MyWeek & "' OR [DepartWk] = '" & MyWeek & "' " & _
-
"OR ([ArrWk]<'" & MyWeek & "' and [DepartWk] > '" & MyWeek & "')) " & _
-
"AND ([ArrYear] = '" & MyYear & "')"
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: -
-
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
-
-
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("Pleas e 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 = "rptCabinOccupa ncy"
MyFilter = "qryWeekSum _01"
DoCmd.OpenRepor t 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 = "rptCabinOccupa ncy"
DoCmd.OpenRepor t MyRpt, acViewPreview, "qryWeekSum_01" , MyCriteria
End Function
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 and interval.
For example you may wish to find all the months between the dates
'2004-02-14' and '2004-08-04'. You would maybe use a function where you pass
in those starting and ending dates and the interval 'month' and you'd get
back a list...
|
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 for an answer on HOW to do this--I don't
necessarily need it to be written for me (although it would not go
unappreciated!).
|
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),
exchangecode varchar(6),
|
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 periods.
What I need to do is take a given review date and find out which date
in my pay periods table it's closest to, above or below.
Any help is greatly appreciated.
-Josh
|
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 to keep the data regarding experience but i need to avoid time overlapping. I use the following tables - among others- EmployeeTb(means employee's table, Edu_ExperTb (means educational experience table) and Prof_ExperTb (means all other experience...
| |
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 parameters and to return the current periods values. (Between And )
For the previous-period query I have used: Between Date() And DateAdd("m",-6,Date())
How do I show both sets of results in one report????
|
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 date ranges:
December 31, 2006 January 13, 2007 # doesn't earn
January 14, 2007 January 27, 2007 # does earn
January 28, 2007 February 10, 2007 # doesn't
|
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 form I have put all the employee data on a label. There are another text boxes that user must put in when the an emploee wants to start leave and end leave. When user click on submit button it will check wheter the empoyee already submitted a leave...
|
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 instance, I would give 01/01/2008, period equals 3 months and maximum date equals 01/01/2009, and the method should return periods like "01/01/2008-03/31/2008","04/01/2008-06/30/2008","07/01/2008-09/30/2008","10/01/2008-12/31/2008".
The code looks like:...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 we have to send another system
| |