Solved

DLookup Statement w/ Multiple Criteria: Error

Posted on 2013-05-17
9
416 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
  • 7
  • 2
9 Comments
 
LVL 49

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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 49

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now