Link to home
Start Free TrialLog in
Avatar of LoveToSpod
LoveToSpodFlag 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.
ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LoveToSpod

ASKER

Patrick

I'm getting the following error in the MaxDate line: "DataType mismatch in criteria expression"
as userid is number, leave out the additional quotes:

MaxDate = DMax("[ChangeDate]", "[tblUserChanges]", "[Actioned] = True AND [UserID] = " & Me.UserID & )
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 & "'")
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
peter - hehehe - and I assume patrick's popped out for lunch (and maybe a cheeky pint!)
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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
loopup - lookup