Solved

Ms Access DLookup with multi criteria and a Null value

Posted on 2014-10-30
5
879 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 35

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

776 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