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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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