Help with Dlookup to grab value in previous record

gcot

New Member
Joined
Feb 4, 2004
Messages
28
I created an expression based on the response in this post

http://www.mrexcel.com/forum/showthread.php?t=243389&highlight=find+previous+records

Unfortunately the expression I created in the query gives me #Error

This expression is part of a query that has the login and logout times for call center agents.

What I want to do is: If the Agent logs out (eventType=7), grab the login time (previous record based on date/time stamp which is eventDateTime is query) for this agent.

Every logout will have a login.

Query = AgentLoggedInTimeQuery
Agents = resourceName
Logout = eventType 7

LoginTime: IIf([eventType]=7,(DLookUp("eventDateTime","AgentLoggedInTimeQuery","resourceName='" & [resourceName] & "' AND eventDateTime=#" & DMax("eventDateTime","AgentLoggedInTimeQuery","resourceName='" & [resourceName] & "'") & "#")),Null)

Any ideas on what I'm doing wrong?

Any help is appreciated.

Thanks,

Gilles
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
See if a subquery helps you --
Code:
LoginTime: Iif([event type]=7,(SELECT Max([eventDateTime] FROM AgentLoggedInQuery AS A WHERE A.[resourcename]=AgentLoggedInQuery.[resourcename] AND A.[eventDateTime]<AgentLoggedInQuery.[eventDateTime]),Null)

Denis
 
Upvote 0
Hi Denis,

I tried the subquery you suggested in the expression builder (not sure if that's right) but I'm getting a message that it needs a closing parenthesis or bracket. I tried several variations adding them where it seemed logical but still doesn't work.

Two questions:

1. Does the subquery go in the expression builder?
2. If yes, then what am I missing?

I'm sure it's something simple but I'm a novice at Access so it's not apparent to me.

Thanks for your help,

Gilles

See if a subquery helps you --
Code:
LoginTime: Iif([event type]=7,(SELECT Max([eventDateTime] FROM AgentLoggedInQuery AS A WHERE A.[resourcename]=AgentLoggedInQuery.[resourcename] AND A.[eventDateTime]<AgentLoggedInQuery.[eventDateTime]),Null)

Denis
 
Upvote 0
Hmmm... make that 3 parentheses. Sorry, I typed straight into the response box without checking first :oops:

Try this:
Code:
LoginTime: Iif([event type]=7,(SELECT Max([eventDateTime]) FROM AgentLoggedInQuery AS A WHERE A.[resourcename]=AgentLoggedInQuery.[resourcename] AND A.[eventDateTime]))

Denis
 
Upvote 0

Forum statistics

Threads
1,214,913
Messages
6,122,207
Members
449,074
Latest member
cancansova

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top