Solved

Access 2007 query between two dates

Posted on 2010-09-14
9
699 Views
Last Modified: 2013-11-30
This is the first time I have ever tried to query for something other than an exact value found in a table. I simply have 4 fields  Name, Hours, StartDate, EndDate. I would like to be able to enter any of the following criteria and return records matching the criteria. My difficulty is that I don't know what to do for the dates. Do I need a table that will store these four values? Can I create a temporary variable? Where do I specify the search criteria? Query? Function?

Thanks in advance!
0
Comment
Question by:timamartin
  • 4
  • 4
9 Comments
 
LVL 13

Expert Comment

by:MWGainesJR
ID: 33675094
Whats the criteria?
are the 4 fields in the same table?
0
 

Author Comment

by:timamartin
ID: 33675122
The original table has 10 fields I created a new table to store the user inputs that has 4+1 fields.
0
 
LVL 13

Expert Comment

by:MWGainesJR
ID: 33675133
what are you wanting to query?
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

Author Comment

by:timamartin
ID: 33675164
I would like to search for all records between date "A" and date "B" as well as optionally name and hours.
0
 
LVL 13

Expert Comment

by:MWGainesJR
ID: 33675181
select name, hours from table where startdate >= date and enddate<= date
0
 

Author Comment

by:timamartin
ID: 33675226
startdate >= date and enddate<= date

So where do the values stardate and enddate get stored prior to passing them to a query?
0
 
LVL 1

Expert Comment

by:innosys
ID: 33675314
cdate is a function will help you build a date from string and the you can compare dates with it
try it
0
 
LVL 13

Accepted Solution

by:
MWGainesJR earned 500 total points
ID: 33675416
sub query()
dim sdate as string
dim edate as string
dim qry as string

sdate = format(inputbox("Enter Start Date"), "mm/dd/yyyy")
edate = format(inputbox("Enter End Date), "mm/dd/yyyy")
qry = "Select name, hours from table where startdate >= " & sdate & " and enddate <= " & edate
'rest of code (recordset or output to spreadsheet or file)
end sub
0
 

Author Closing Comment

by:timamartin
ID: 33675438
Ohhhhhh...I see. Thanks for your assistance that is what I need.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question