L
Lisa Reber
This started back on Feb 20, with lots of great
information from John V. It has gotten off the subject of
poor table design to a query using DMax. Here's my
original request:
recently added a payments table that shows
latest contribution, how much money is membership
and how much is support, etc. Have linked the payments
to contacts successfully, but now have a problem with
pulling out the most recent renewal date (membership
date + 365). A member has many payments, thus many
renewal dates, and my reminder notice works off a query
prompting for a range of renewal dates. As I re-read
this, it sounds like it should work, but doesn't.
Hi John - finally got to (had to) get this done. In your
Why does this work? I ran it the first time without any
memberID parameters, and got the highest membership date
in all member$ payments, which makes sense. Adding the
, "[MemberID] = " & [MemberID])
optional criteria gave me exactly
what I wanted (THANKS!) each member's most recent
membership payment, and I'm curious. I'd also like to be
able to re-create it myself in the future! Thanks also for
clarifying syntax, below. I guess maybe you have already
answered my question above with the comments about SQL
below. But I'm at the point where I know that I don't know
anything, I just want to.
Second, the way I have this set up is:
Contacts Table
Payments Table
Query: "Contacts with Payment info" looking at both tbls
qryMaxMemberDate looks at above
query: "Renew or Second Letter" (with membership
date prompt to extract only a range of dates) looking at
qryMaxMemberDate. This third-generation query seems to be
cumbersome, not in itself, but in that it has to drill
down (or up?) to produce the desired results. More a
policy question than procedure, I guess, but it would be
good to do stuff correctly henceforth, after almost three
years of blind guesses.
Regards, Lisa
information from John V. It has gotten off the subject of
poor table design to a query using DMax. Here's my
original request:
recently added a payments table that shows
latest contribution, how much money is membership
and how much is support, etc. Have linked the payments
to contacts successfully, but now have a problem with
pulling out the most recent renewal date (membership
date + 365). A member has many payments, thus many
renewal dates, and my reminder notice works off a query
prompting for a range of renewal dates. As I re-read
this, it sounds like it should work, but doesn't.
Hi John - finally got to (had to) get this done. In your
A Query with a criterion on the membership date of
=DMax("[MembershipDate]", "[PaymentTable]", "[MemberID] = " & [MemberID])
will select only the most recent membership record.
Why does this work? I ran it the first time without any
memberID parameters, and got the highest membership date
in all member$ payments, which makes sense. Adding the
, "[MemberID] = " & [MemberID])
optional criteria gave me exactly
what I wanted (THANKS!) each member's most recent
membership payment, and I'm curious. I'd also like to be
able to re-create it myself in the future! Thanks also for
clarifying syntax, below. I guess maybe you have already
answered my question above with the comments about SQL
below. But I'm at the point where I know that I don't know
anything, I just want to.
Second, the way I have this set up is:
Contacts Table
Payments Table
Query: "Contacts with Payment info" looking at both tbls
qryMaxMemberDate looks at above
query: "Renew or Second Letter" (with membership
date prompt to extract only a range of dates) looking at
qryMaxMemberDate. This third-generation query seems to be
cumbersome, not in itself, but in that it has to drill
down (or up?) to produce the desired results. More a
policy question than procedure, I guess, but it would be
good to do stuff correctly henceforth, after almost three
years of blind guesses.
Regards, Lisa
-----Original Message-----
Not there yet, tho' it's on my mind. So does it need allDMax("[field name]", "[table name]", "<optional criteria>")
.
the paren's quotes and brackets? thanks one mo' time!
It needs two parentheses: any Function call is followed by a pair of
parentheses containing its arguments. So you need
DMax( <some stuff> )
The "stuff" in this case consists of three text strings. They can be
literal text strings in quotation marks or they can be string
variables; but the first of them must be the name of a Field (the
field you're finding the maximum value *of*); the second of them must
be the name of a Table or a Query (the domain, it's called; where to
find this field).
The third argument is optional; it's a valid SQL WHERE clause without
the word WHERE that selects which records to consider in searching for
the maximum value. It's the trickiest because it's very often built up
piecewise from string constants and VBA variables or form referernces.
For instance to fing the maximum (most recent) date for a particular
customerID in a table of sales to customers, you might have
DMax("[SaleDate]", "[tblSales]", "[CustomerID] = " &
Me![txtCustomerID])
The square brackets around fieldnames and tablenames or control names
are optional *unless* those names contain blanks or special
characters, in which case they are obligatory - I habitually include
them, just as a visual reminder to me that I'm talking about a table
or form object rather than a VBA variable.