From: No1momof3 on 7 May 2010 10:36 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
From: KenSheridan via AccessMonster.com on 7 May 2010 14:04 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/Forums.aspx/access-queries/201005/1
|
Pages: 1 Prev: How to Analyze Attributes in a Query Next: Delete Records from Table using Query Results |