Skip to content
Advertisement

Running Dlookup() on a query with row count column as criteria (MS access)

Im trying to run Dlookup to return all values of a column in a query’s results. As Dlookup can only return 1 result I have added a row count column to the query so I can use the row count as the criteria for the Dlookup.

My query results look like this in the results Query design view Query results 2

In SQL view the query is as follows:

I have added the row count with the following video (https://www.youtube.com/watch?v=HWbpzETe-M0), let me know if more information about this is needed.

The query results look to be correct, however, when using the Dlookup (beneath) it returns null.

When I try and return the [NO] column value it works.

Advertisement

Answer

I don’t have your data, so can’t run a full test, but I ran something similar using my RowNumber function (below), and DLookup was able to filter on the returned rownumber (your [NO]) and return a value from another field.

So, try to use this function (your SQL will need minor adjustments, see in-line comments, please):

The full story can be found in my project VBA.RowNumbers.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement