?
Solved

Getting DLookup to return a Null value in Access - VB6

Posted on 2006-07-18
7
Medium Priority
?
454 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
  • 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 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

807 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