Avatar of LoveToSpod
LoveToSpod
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Dlookup top record with two criteria

Hi there,

I have a table called tblUserChanges. Within this table there are the following fields:
[Change] - Text
[ChangeDate] - DateTime
[Actioned] - YesNo
[UserID] - Number

I would like to get the latest [Change] value (using [ChangeDate]), where [Actioned] = True and [UserID]= Me.UserID

Please help! Cheers, LoveToSpod.
Microsoft Access

Avatar of undefined
Last Comment
GRayL

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Patrick Matthews

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
LoveToSpod

ASKER
Patrick

I'm getting the following error in the MaxDate line: "DataType mismatch in criteria expression"
Sham Haque

as userid is number, leave out the additional quotes:

MaxDate = DMax("[ChangeDate]", "[tblUserChanges]", "[Actioned] = True AND [UserID] = " & Me.UserID & )
SOLUTION
Sham Haque

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
peter57r

Is MaxDate Dim-ed as a date variable?

If you are using UK dates try:
MsgBox DLookup("[Change]", "[tblUserChanges]", "[ChangeDate] = #" & format(MaxDate,"yyyy-mm-dd") & "# AND [UserID] = '" & Me.UserID & "'")
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
SOLUTION
peter57r

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Sham Haque

peter - hehehe - and I assume patrick's popped out for lunch (and maybe a cheeky pint!)
GRayL

Try making this the control source for a textbox on the form on which you have the textbox - UserID

=DLookup("Change",'tblUserChanges","ChangeDate=DMax("ChangeDate", "tblUserChanges", "Actioned = True AND UserID = " & Me.UserID & ") AND Actioned = True AND UserID = " & Me.UserID & """)

SOLUTION
GRayL

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
GRayL

loopup - lookup
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.