Solved

Ms Access - VBA DLookup returning Null Values

Posted on 2008-10-16
2
929 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

785 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