Solved

Ms Access DLookup with multi criteria and a Null value

Posted on 2014-10-30
5
852 Views
Last Modified: 2014-10-30
Hello all,

I can not figure out what I am doing wrong with this syntax. I know that I am screwing thing up when filtering data [RemovedBy] for Null only data. My guess is that I am missing or miss placed quotation marks. Help!!!!

DLookup("LotNumber","CM_SOLUTION_USAGE", "[Station] = " & [Forms]![Station Replenishment]![Station] & " And [Solution] =  " & [Forms]![Station Replenishment]![cmbSolution]  & " And [RemovedBy]Is Null")

Thank you!!!
0
Comment
Question by:Cobra967
  • 2
  • 2
5 Comments
 
LVL 84
ID: 40413590
Is Station or Solution are Text fields:

DLookup("LotNumber","CM_SOLUTION_USAGE", "[Station] = '" & [Forms]![Station Replenishment]![Station] & "' And [Solution] =  '" & [Forms]![Station Replenishment]![cmbSolution]  & "' And IsNull([RemovedBy])")
0
 

Author Comment

by:Cobra967
ID: 40413607
[Station] is a number, [Solution] is a text and [RemovedBy] is a text.
0
 

Author Comment

by:Cobra967
ID: 40413677
Thank you Scott but it does not work yet, I get error Run-time 3464.
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 400 total points
ID: 40413825
Try this:

DLookup("LotNumber","CM_SOLUTION_USAGE", "[Station] = " & [Forms]![Station Replenishment]![Station] & " And [Solution] =  '" & [Forms]![Station Replenishment]![cmbSolution]  & "' And IsNull([RemovedBy])")
0
 
LVL 34

Assisted Solution

by:PatHartman
PatHartman earned 100 total points
ID: 40413857
If you are still having syntax issues, create a string variable and populate it outside the DLookup().  That way you can look at it directly and see that the quotes are where they should be.

Dim strWhere as String
strWhere = "[Station] = " & [Forms]![Station Replenishment]![Station] & " And [Solution] =  '" & [Forms]![Station Replenishment]![cmbSolution]  & "' And [RemovedBy] Is Null"
DLookup("LotNumber","CM_SOLUTION_USAGE", strWhere)

Also, if you are running the code within the form [Station Replenishment], you can shorten the expression by using the Me. reference which also makes it easier to read.

strWhere = "[Station] = " & Me.Station & " And [Solution] =  '" & Me.cmbSolution  & "' And [RemovedBy] Is Null"
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now