A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Date query allowing user to enter dates



 
 
Thread Tools Display Modes
  #1  
Old May 7th, 2010, 03:36 PM posted to microsoft.public.access.queries
No1momof3
external usenet poster
 
Posts: 3
Default Date query allowing user to enter dates

HI

I have a DB where I am trying to set up a search criteria using 2 tables and
one field out of each.

Table - Services Field - Service
Table - Appointments Field - Appointment Date (format = dd/mm/yyyy)

How can I set up a query where the user can input to select appointments
between 2 dates ie: 01/04/2010 - 30/04/2010 and service (ie exams)

I notice when I do a filter it allows me to select the dates from the
calendar - can this be done in a search criteria and would I be able to make
the list of services available in a drop down box.

I am relatively new to DB and don't use it often so need easy instructions.

many thanks

Irene
  #2  
Old May 7th, 2010, 07:04 PM posted to microsoft.public.access.queries
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default Date query allowing user to enter dates

Irene:

To be able to select a service form a combo box you'd need to create a
dialogue form in which you can enter the dates and select the service. A
query can then reference the controls on the form as parameters. You don't
say on what fields the two tables are related, however, so for this example
I'll call them SomeField. The query would then be something like this;

PARAMETERS
Forms!YourFormName!txtStartDate DATETIME,
Forms!YourFormName!txtEndDate DATETIME,
Forms!YourFormName!cboService TEXT ( 50 );
SELECT column list
FROM Services INNER JOIN Appointments
ON Services.SomeField = Appointments.SomeField
WHERE [Appointment Date] = Forms!YourFormName!txtStartDate
AND [Appointment Date] Forms!YourFormName!txtEndDate+1
AND Service = Forms!YourFormname!cboService;

For the column list include whatever columns form one or both tables you want
returned.

In the form, to limit the cboService combo box's list to those between the
selected appointment dates the RowSource property of the combo box would be
along these lines:

PARAMETERS
Forms!YourFormName!txtStartDate DATETIME,
Forms!YourFormName!txtEndDate DATETIME;
SELECT Service
FROMServices INNER JOIN Appointments
ON Services.SomeField = Appointments.SomeField
WHERE ([Appointment Date] = Form!txtStartDate
OR Form!txtStartDate IS NULL)
AND ([Appointment Date] Form!txtEndDate+1
OR Form!txtEndDate IS NULL)
ORDER BY Service;

In the AfterUpdate event procedures of txtStartDate and txtEndDate requery
the combo box with:

Me.cboService.Requery

When you enter a date into each of the text boxes the combo box's list will
be progressively restricted to show only the services with appointments dates
in matching rows in Appointments between the two dates.

On the form you can then have a button to open the first query, or better
still a form or report which uses the query as its RecordSource property.

Note that in the above queries the parameters are declared. This is
especially important with date parameters as these might otherwise be
incorrectly interpreted as arithmetical expressions rather than date values
and give the wrong results.

Ken Sheridan
Stafford, England

No1momof3 wrote:
HI

I have a DB where I am trying to set up a search criteria using 2 tables and
one field out of each.

Table - Services Field - Service
Table - Appointments Field - Appointment Date (format = dd/mm/yyyy)

How can I set up a query where the user can input to select appointments
between 2 dates ie: 01/04/2010 - 30/04/2010 and service (ie exams)

I notice when I do a filter it allows me to select the dates from the
calendar - can this be done in a search criteria and would I be able to make
the list of services available in a drop down box.

I am relatively new to DB and don't use it often so need easy instructions.

many thanks

Irene


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/201005/1

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:42 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.