Solved

Access 2007 query between two dates

Posted on 2010-09-14
9
696 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now