How do I find the last date?

J

JWCrosby

I have a contact management database based mostly on the Contact Management
wizard that comes with Access 2003. The table of Contacts has a ContactID
field (primary) and the Calls table has the list of call details, including a
date field (linked on the ContactID field).

On the main form that shows all the info about the contact, I want a field
that will show the date of the last contact, which would be the most recent
date in the Calls table associated with that Contact.

The original developer had used a public function (below) that used the
DLast function to return that date, but it doesn't seem to be working
consistently correctly. I'm assuming there's a better way, but I've reached
the limitation of my knowledge of Access to know what it is.

Public Function LastDate(CID)
Dim mydate
On Error GoTo errout
mydate = DLast("CallDate", "tblCalls", "[ContactID] =" & CID)
If IsNull(mydate) Then
LastDate = "None"
Else
LastDate = DateValue(mydate)
End If
errout:
End Function

Can someone help get me out of the dark?

Thanks in advance.

Jerry
 
S

Sprinks

JW,

DFirst and DLast actually return a random value from the domain specified.
The find the most recent, use the DMax function:

....
mydate = DMax("[CallDate]", "tblCalls", "[ContactID] =" & CID)
....

Sprinks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top