it gives me the message "syntax error in parameter clause"
i don't know if i have to post to each reply or not...I tried both
suggestions and am still stuck
and neither one will show me the drop down list.
--
terri
:
Terri:
Firstly a few points to tidy up the SQL statement:
1. You shouldn't need the DISTINCTROW option. Its really a hangover from
the days when Access couldn’t handle subqueries.
2. As you are returning rows from just one table you don't need to qualify
the column names with the table name.
3. As your table and column names don't include any spaces or other special
characters you don't need to wrap them in brackets.
As for correlating the combo box with the text box you've almost answered
your own question when you say 'where the admit date is between the
[drgstartdate] and the [drgenddate]' as that's very close to what you need in
the SQL statement.
As the parameter is a date/time one its quite important to declare it as
date/time data type. Otherwise Access might misinterpret it as an
arithmetical expression not a date.
You might want the combo box to list its items in some order, so you can add
an ORDER BY clause. For this example I've sorted by strDRGdescription, but
you can change this to whatever you prefer.
So putting that all together the combo box's RowSource property would be
like this:
PARAMETERS Forms!YourForm!admitdate DATETIME;
SELECT strdrg, strDRGdescription, intWeight, drgstartdate, drgenddate
FROM DRGtable1
WHERE Forms!YourForm!admitdate BETWEEEN drgstartdate AND drgenddate
ORDER BY strDRGdescription;
To get the combo box to list just the rows where the date range includes the
date entered in the admitdate control you need to requery the combo box in
the AfterUpdate event procedure of the admitdate text box with:
Me.YourComboBox.Requery
You'll need to change the name of the form and combo box in the above to
your actual ones of course.
If you are not familiar with entering code in event procedures this is how
its done:
Select the admitdate control in form design view and open its properties
sheet if its not already open. Then select the After Update event property
in the properties sheet. Click on the 'build' button; that's the one on the
right with 3 dots. Select 'Code Builder' in the dialogue, and click OK. The
VBA window will open at the event procedure with the first and last lines
already in place. Enter the line of code between these two existing lines.
One final caveat:
The SQL statement as written above assumes that the values in the
drgstartdate and drgenddate columns are all dates with a zero time of day
(there's not really any such thing as a date value per se in Access, only
date/time values). If there is any possibility that this might not be the
case (and it could well not be without you being aware of it) the SQL
statement might not return some relevant rows. You can prevent this by
writing it slightly differently:
PARAMETERS Forms!YourForm!admitdate DATETIME;
SELECT strdrg, strDRGdescription, intWeight, drgstartdate, drgenddate
FROM DRGtable1
WHERE Forms!YourForm!admitdate >= drgstartdate
AND Forms!YourForm!admitdate < DATEADD("d",1,drgenddate)
ORDER BY strDRGdescription;
This in effect looks for rows where admit date is on or after the
drgstartdate and before the day following the drgenddate. If you are not
absolutely confident that these columns contain only dates with a zero time
of day, then use the latter SQL statement to be sure of missing nothing.
Ken Sheridan
Stafford, England
:
I have a form with a combo box that selects the drg from a table...works just
fine:
select distinctrow
[DRGtable1].[strdrg],[DRGtable1].[strDRGdescription],[DRGtable1].[intWeight],[DRGtable1].[drgstartdate],[DRGtable1].[drgenddate] from [DRGtable1];
Now i want that combo box to select the correct drg based on a text box
the user fills in called [admitdate] where the admit date is between
the [drgstartdate] and the [drgenddate].
reason is there will be two drgs with the same number like 470, but for
oct 1 2007 through sept 30 2008, 470 is weighted at 5..and for the next
year it's weighted at say 6.
i'm coming up on Oct 1st where these weights will change...can you help me?
i'm eating too much chocolate trying to do this!