Solved

Getting DLookup to return a Null value in Access - VB6

Posted on 2006-07-18
7
443 Views
Last Modified: 2012-06-22
Hello experts,

This should be pretty easy but I cannot figure it out.  I am new to VB and having problems.

I am trying to make a form in Access that will allow the user to input their employee number into a textbox.  Once they click the button, it will look for thier name in a table and retreive their info or return a Null value if the number is not found.  I have had not problems having it find records that are there, but I cannot figure out how to make it return a Null if there is no record found.

Here is my code:

' NumberInputTxt , FirstNameTxt , and ValidTxt  are all textboxes
' identipass is the table I am looking in

' the problem is I cannot get varX to = Null.  I have also tried if varX="" which did not work


Private Sub numberinputtxt_Click()

Dim CardNumber As String
Dim varX As Variant

CardNumber = NumberInputTxt.Text

varX = DLookup("[First]", "Identipass", "[Number]= " & CardNumber)

FirstNameTxt = varX

If varX = Null Then
ValidTxt = "Null"

Else

ValidTxt = "Found"
End If

End Sub

----------------------------------------------------------

Thanks in advance!
0
Comment
Question by:paries
[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
  • 4
  • 2
7 Comments
 
LVL 34

Expert Comment

by:flavo
ID: 17133256
If varX Is Null Then
ValidTxt = "Null"

Dave
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 17133291
DLOOKUP always returns null if no record foind

Flavo has given u the right syntax. The other way  is    If IsNull(varx) = True then



Alternativly, u can use NZ to return a string instead

varX = NZ(DLookup("[First]", "Identipass", "[Number]= " & CardNumber),"")
if varX = "" then
    msgbox "Not found"


0
 

Author Comment

by:paries
ID: 17133436
If varX Is Null then    gave me a runtime error 424 for some reason.  The other suggestion worked great.  Thanks
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 34

Expert Comment

by:flavo
ID: 17133475
what?
0
 
LVL 34

Expert Comment

by:flavo
ID: 17133500
Well I'll be...I doesn't work :-(

Dave
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17133615
Dave, thinking about it, I think may be it will work for object references only
0
 
LVL 34

Expert Comment

by:flavo
ID: 17134297
Yeap :-(
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

733 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