?
Solved

Access 2007 query between two dates

Posted on 2010-09-14
9
Medium Priority
?
705 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

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 2000 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

771 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