Solved

DLookup Statement w/ Multiple Criteria: Error

Posted on 2013-05-17
9
426 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 50

Accepted Solution

by:
Gustav Brock earned 500 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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 50

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

728 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