?
Solved

DLookup Statement w/ Multiple Criteria: Error

Posted on 2013-05-17
9
Medium Priority
?
427 Views
Last Modified: 2013-05-17
Hello ~ I am intending to find the value of "ttSitus" from the table "tblTimeTracking" where BOTH the "ttPerson" = "ttPerson" in the record on the form  AND the largest "ttID" for that same "ttPerson".

Right now, the following statement is retrieving the "ttSitus" with the largest "ttID"; regardless of "ttPerson".

Any ideas for correct syntax?

=DLookUp("[ttSitus]","tblTimeTracking","[ttPerson] = forms!frmTimeTracking!ttPerson and ([ttID]=dmax(forms!frmTimeTracking!ttID))")

also tried:

=DLookUp("[ttSitus]","tblTimeTracking","[ttPerson] =" & [Forms]![frmTimeTracking]![ttPerson] And [ttID]=Max([ttID]))

also tried:

=DLookUp("[ttSitus]","tblTimeTracking","[ttPerson] =" & [Forms]![frmTimeTracking]![ttPerson] And "[ttID]=" & Max(DLookUp("[ttID]","tblTimeTracking","[ttID]")))

Definitely missing something here...
To dreamtime; WCB tomorrow.

Many Thanks ~ Jacob
0
Comment
Question by:Chi Is Current
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 2
9 Comments
 
LVL 51

Accepted Solution

by:
Gustav Brock earned 2000 total points
ID: 39174054
First the max:

DMax("[ttID]","tblTimeTracking",ttPerson] = " & Forms!frmTimeTracking!ttPerson & "")

Then:

=DLookUp("[ttSitus]","tblTimeTracking","[ttPerson] = " & Forms!frmTimeTracking!ttPerson & " And [ttID] = " & DMax("[ttID]","tblTimeTracking",ttPerson] = " & Forms!frmTimeTracking!ttPerson & "") & "")

or, if Person is a string:

=DLookUp("[ttSitus]","tblTimeTracking","[ttPerson] = '" & Forms!frmTimeTracking!ttPerson & "' And [ttID] = " & DMax("[ttID]","tblTimeTracking",ttPerson] = '" & Forms!frmTimeTracking!ttPerson & "'") & "")

/gustav
0
 
LVL 2

Author Comment

by:Chi Is Current
ID: 39174068
Thank you, Gustav, for your reply!!!

Person IS a string; however, this code does not resolve:
"Invalid syntax" - missing operator or operand or invalid character or comma or text without surrounding quotation marks.   ???
0
 
LVL 2

Author Comment

by:Chi Is Current
ID: 39174084
OK, a '[' is needed, on ttPerson], second line ...

But still not there = expression too long  ????
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Author Comment

by:Chi Is Current
ID: 39174093
OK + another ":

=DLookUp("[ttSitus]","tblTimeTracking","[ttPerson] = '" & Forms!frmTimeTracking!ttPerson & "' And [ttID] = " & DMax("[ttID]","tblTimeTracking", "[ttPerson] = '" & Forms!frmTimeTracking!ttPerson & "'") & "")

DOES RESOLVE, but not catching the last ttSitus for ttPerson  w/ Dmax ttID...
???
0
 
LVL 2

Author Comment

by:Chi Is Current
ID: 39174105
Hmmmmmmm......

This does work, sort of.  It catches a previous value of ttSitus, not necessarily the last one for ttPerson...

BTW I am using this function as the Default property of a control on a form.
0
 
LVL 2

Author Comment

by:Chi Is Current
ID: 39174187
OOOOOOOOOOOOOOOOK!!!!!  Works just fine!!!  I think the problem is using the function as the default value.  Gets set prior to the field's update......

I'll but into an Event...

'Should have gone to bed......

Thank you for the beautiful code and the lesson.

Best Regards, Jacob
0
 
LVL 2

Author Comment

by:Chi Is Current
ID: 39174202
P.S. ~ That did it.  On AfterUpdate for another control!!!!

THANK YOU!!!!
0
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 39174259
You are welcome!

/gustav
0
 
LVL 2

Author Comment

by:Chi Is Current
ID: 39176753
/gustav ~

Follow-up posted here:
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_28132114.html

Revising same code to work with a DATE field.
Results in null.

Care to comment?

Best Regards,  Jacob
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question