Solved

Ms Access - VBA DLookup returning Null Values

Posted on 2008-10-16
2
944 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

717 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