Gary Walter said:
Bec_FS said:
Thank you so much for taking the time to read this, and even more so if you
respond!!!
I am trying to get Site Fidelity for a group of species. I figured this
would be a simple query, but it is turning out not to be. I have a table
with a bunch of animal species, pit-tag, and data captured. Sometime and
pit-tagged animal was captured more than once per year, and sometimes
captured multiple years. I was trying to query where pit-tag was in
2003
AND
2004, but that does not seem to work. I tried using an OR between dates,
but then it gives me the pittags that were in 2003, but not 2004 or vica
versa. I want the pit-tag if it was captured in 2003 AND 2004, and so on
2004 AND 2005, 2005 and 2006. Can you not use the AND in criteria for one
field? Hope this makes sense!
When Access is looking at a record in your query
and deciding whether to return it or not, its capture
date field cannot be 2003 and 2004 at the same time.
It is either one year or the other.
Does that make sense?
One strategy would be to switch to a totals query,
decide what gets included in using
WHERE Year([capturefield]) IN (2003, 2004)
i.e., only include in a group if 2003 OR 2004...
then, after get your groups, weed out groups that
don't have both 2003 AND 2004
HAVING Min(Year([capturefield]))<>Max(Year([capturefield])
i.e., if min was equal to max in the group,
you'd know did not have both 2003 AND 2004...
Another way of looking at your data would involve
using 3 instances of your table...
(you probably only need 2 instances, so this may be
more an exercise in what is possible, but learning
what you need as well..if that makes sense)
In a new query add your table 3 times.
Right-mouse click on one table,
choose "Properties"
and change "Alias" to "HereAndNow"
Likewise, change Alias of second table to "Previous"
and third table to "Next"
Drag-and-drop field(s) from "HereAndNow" to
"Previous" that will "match them up" (you know your
data).
Likewise, set join(s) from "Previous" to "Next."
Double-click on top of table of "HereAndNow"
to select all fields, then drag-and-drop multiselection
down to a "Field" row in grid.
I'm not entirely clear how some field ends up being a "year"
so continue as above assuming you had a "capturefield"
that contained the date of capture, and "year" was calculated
by "Year([capturefield])"
If so, double-click on [capturefield] in each table
to add them to end of grid.
Field: capturefield
Table: HereAndNow
Sort:
Show: <checked>
Criteria:
Or:
Field: capturefield
Table: Previous
Sort:
Show: <checked>
Criteria:
Or:
Field: capturefield
Table: Next
Sort:
Show: <checked>
Criteria:
Or:
(maybe you don't have to do this, but) change
"Field" rows of these 3 columns to get "year"
and give each an alias to keep track of them .
Field: HNYear: Year([capturefield])
Table: HereAndNow
Sort:
Show: <checked>
Criteria:
Or:
Field: PrevYear: Year([capturefield])
Table: Previous
Sort:
Show: <checked>
Criteria:
Or:
Field: NextYear: Year([capturefield])
Table: Next
Sort:
Show: <checked>
Criteria:
Or:
And now -- why we did all this ---
set Criteria for "Previous" and "Next" years
to define their time relationship to "HereAndNow."
Field: PrevYear: Year([capturefield])
Table: Previous
Sort:
Show: <checked>
Criteria: Year(HereAndNow.capturefield) - 1
Or:
Field: NextYear: Year([capturefield])
Table: Next
Sort:
Show: <checked>
Criteria: Year(HereAndNow.capturefield) + 1
Or:
Save the query and see what we are getting.
For a specific record in "HereAndNow,"
if a capture happened for that species
in the previous and next year, it will be
returned (possibly more than once because
of multicaptures in a year).
As I said earlier this is more than you wanted
(just an exercise in "past/present/future").
My guess is you would probably want to delete the
"Previous" table from the query and set
Criteria for HNYear to year you are interested in.
Plus, because you can have more than one capture
for a species in one year, you will probably need to
--lose the primary key (delete column for "HereAndNow"
ID or whatever you named it)
--lose the "full date" capturefield column (if it exists)
--set Property of query for Distinct Values
to return only one record for each species.
Well...that might be another approach to the problem...