"Jeff" <(E-Mail Removed)> wrote in message
news:A9D738B4-7E33-4F28-B941-(E-Mail Removed)...
> Hi Ken,
>
> Thank you for your quick response, I test your code for a single vaccine
> and
> it works. I wonder if I should narrow the range of my tbVaccine first
> before
> counting. That is, I should retrieve my tbVaccine with [InjectDate]
> Between
> Me![StartDate] And Me![EndDate] first, then count the vaccine with this
> lot
> of records.
This is what the query is doing now. In a totals query, the WHERE clause is
applied first in order to filter the dataset, then ACCESS does the counting.
> So Access doesn't need to go through tbVaccine for each Vaccine
> and dose number. I don't know how to put this in code, any help will be
> appreciated.
>
> Yes, [Injectdate] should be a date datatype field. I used String datatype
> when I wrote the code. I'll fix it, Thank you.
Be sure that you have the StartDate and EndDate controls on the form
formatted as "short date" or some other date format; this will let ACCESS
know that you are providing a date value in the WHERE clause. Else, do this:
Set rst = dbs.OpenRecordset("SELECT Count([TradeNm]) " & _
"As TheCount FROM tbVaccine WHERE [TradeNm] = " & _
"'VaccineA' And [VaccNth] = '1' And [InjectDate] " & _
"Between " & Format(Me![StartDate], "\#mm\/dd\/yyyy\#") & _
" And '" & Format(Me![EndDate], "\#mm\/dd\/yyyy\#"), _
dbOpenForwardOnly, dbReadOnly)
--
Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/