Solved

Access 2007 query between two dates

Posted on 2010-09-14
9
701 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

There was an incident about the POP3 issue for the double read receipts and delivery receipts in Exchange 2013.  There was huge research been done and found solution for the duplicate mails. Especially when the user gets  duplicate mails.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

726 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