Thomas Kerber
Thomas Kerber

Reputation: 99

DLookup not resolving

I am trying to find a field value in a table based on another value in the same record using the DLookup function.

[UsesPrm] is the boolean field to be returned.

tZ003_QrySubscription is the table I am searching.

[QryName] is the field to be compared.

qdf.Name is the name of the query to comare against [QryName]

If [QryName] contains "qryTest1", and qdf.Name is set to "qryTest1" I get the error: "Run-time error 2001. You cancelled the previous operation."

booTest = DLookup("[UsesPrm]", "tZ003_QrySubscription", "[QryName] = " & qdf.Name)

The following code statement using a literal works perfectly:

booTest = DLookup("[UsesPrm]", "tZ003_QrySubscription", "[QryName] = 'qryTest1')

Sadly, this little piece of code is inside of a loop where the values in [QryName] and qdf.Name both change with each iteration, so using a literal is out of the question.

How do I get the actual name (qdf.Name) to compare to a field string value containing the same name?

Upvotes: 0

Views: 44

Answers (1)

Gustav
Gustav

Reputation: 55816

Add the quotes:

booTest = DLookup("[UsesPrm]", "tZ003_QrySubscription", "[QryName] = '" & qdf.Name & "'")

And do take care of non-found lookups:

booTest = Nz(DLookup("[UsesPrm]", "tZ003_QrySubscription", "[QryName] = '" & qdf.Name & "'"), False)

Upvotes: 1

Related Questions