Solved

Ms Access - VBA DLookup returning Null Values

Posted on 2008-10-16
2
935 Views
Last Modified: 2013-12-25
Afternoon,

I have a set of DLookups which populate a text field accoring to what ID number someone puts in another text field. Can someone tell me how I would output a message box if that ID retrn no records? My current code is;

strSPNValue = txtSPN.Value
txtSPNName = DLookup("[spn_name]", "Sel_Historical_SPN_Lookup", "SPN ='" & strSPNValue & "'")

Thanks
0
Comment
Question by:andyb7901
2 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 22730761
Use an If-then block.  If Dlookup returns a Null, then there are no records found.

Dim varLU as Variant
strSPNValue = txtSPN.Value
VarLU =  DLookup("[spn_name]", "Sel_Historical_SPN_Lookup", "SPN ='" & strSPNValue
if isNull(VarLU) then
    MsgBox "No records found"
   ' etc
end if
txtSPNName = VarLU
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 22730834
Or:

txtSPNName = Nz(DLookup("[spn_name]", "Sel_Historical_SPN_Lookup", "SPN ='" & strSPNValue & "'"), "")
If txtSPNName = "" Then
    'do something
End If
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

679 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