Dlookup Function- Using a Parameter in the Criteria

BlueRhinos

Board Regular
Joined
Aug 31, 2007
Messages
83
Within a query, I'd like to add a field using the dlookup function. Instead of using static values in the criteria part of the function, I'd like to use a parameter to keep it dynamic. The online example suggests preceding the field value with Form! to tell Access that the field reference, "Person ID," comes from the current form.

When I use this syntax, i get the following error message: "MS Access can't find the name
Form![Person ID] you entered in the expression.

I've experimented by replacing Form! with:
(1) Query!
(2) [query name].[Person ID]

Here's a visual:
Record:
Person Person ID Manager Manager ID NEW DLoopfield (Manager's Manager)
Dave 1 Scott 2 Donna
Scott 2 Donna 3 Erin

so, my function says give me Manager from Table A where the Person ID = Manager ID from this table.

Can someone help me solve...I can't think of any other intuitive syntax.

Thanks!
BlueRhinos
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
If you are doing this in a query, then you can get the appropriate record for each row by using
MyNewFieldName:Dlookup("YourFieldYouWantReturnedInTheTable", "YourTableName", "[PersonID]=" & [ManagerID])
If the ID field is text then you would need to use quotes on either side:
MyNewFieldName:Dlookup("YourFieldYouWantReturnedInTheTable", "YourTableName", "[PersonID]='" & [ManagerID] & "'")
 
Upvote 0
Bob, this worked!! Thanks for the quick and easy to understand feedback. It was much appreciated.

BlueRhinos
 
Upvote 0

Forum statistics

Threads
1,216,165
Messages
6,129,242
Members
449,496
Latest member
Patupaiarehe

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