Dlookup with DMax on date

poporacer

Registered User.
Local time
Yesterday, 21:55
Joined
Aug 30, 2007
Messages
136
I have a control on a report that I need to set the properties to get the following data. The report has a textBox control called EMP_ID and I have a table called tblDocsIssued. This table has the fields EMP_ID, docDate and docType. I need to get the comment that has the most recent docDate and docType =4 that matches the [EMP_ID] on the report. I tried the following and I think I am close, but not quite there. Probably a quote missing or in the wrong spot. What would be the proper way to do this?
Code:
=Dlookup("comments", "tblDocsIssued", "EMP_ID = '" & [EMP_ID] & "' AND DMax("docDate","tblDocsIssued","docType=4 And Emp_ID='" & [Emp_ID] & "'")")
 
I figured it out. I wasn't thinking about the DMax function being part of the DLookup function and was already enclosed in quotes. So you have to double up on the quotes. Here is the correct version:
Code:
=Dlookup("comments", "tblDocsIssued", "EMP_ID = '" & [EMP_ID] & "' AND DMax(""docDate"",""tblDocsIssued"",""docType=4 And Emp_ID='" & [Emp_ID] & "'"")")
 

Users who are viewing this thread

Back
Top Bottom