By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,148 Members | 765 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,148 IT Pros & Developers. It's quick & easy.

Having trouble with DLookUp in A97...

P: n/a
MLH
I have tried using DLookUp in this manner...

If DLookUp("[ClientID]","tblClients","[HPhone]='2021234567'") Then
MsgBox "Found it!"
End If

I am wondering if that is a misuse of the DLookUp command?

Type mismatch errors keep popping up. Take a look at this
I typed in the immediate window...

?DLookup("[VehicleMake]", "tblVehicleNames",
"[VehicleMake]=GetCurrentVehicleMake()")
Acura

Acura was returned, as expected.

But when I run the following code in a form module, I
get a type mismatch error running the If DLookUp line...

CurrentVehicleMake = Me!VehicleMake
If DLookup("[VehicleMake]", "tblVehicleNames",
"[VehicleMake]=GetCurrentVehicleMake()") Then
Exit Sub
Else
MySQL = "INSERT INTO tblVehicleNames (VehicleMake) SELECT
GetCurrentVehicleMake() AS MyNewMake;"
DoCmd.SetWarnings False
DoCmd.RunSQL MySQL
DoCmd.SetWarnings True
End If

Is it a mistaken belief that if something other than Null is returned
by by the DLookUp function in an If - DLookUp - Then clause
that the If conditional is presumed True and the contents inside the
If - End If wrapper are processed? Have I somehow bastardized the
whole concept, or did this use to work?
Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
MLH
Is it because the DLookUp is returning a string???
A string cannot be evaluated as True or False.
That may be the problem. Here is an example of
a scenario that works - without a hitch...

? dlookup("[vehiclejobid]","tblvehiclejobs","[ownerid]=2")
116

if dlookup("[vehiclejobid]","tblvehiclejobs","[ownerid]=2") then
msgbox "Hello"

Both of the above lines in the immediate window work as expected.
Of course, 116 evaluates to True a heck of a lot more reliably than
does "Acura". If you agree this is the root of my problem, pls let me
know you concur. Am tired of struggling with this.
Nov 13 '05 #2

P: n/a
"MLH" <CR**@NorthState.net> wrote in message
news:09********************************@4ax.com...
Is it because the DLookUp is returning a string???
A string cannot be evaluated as True or False.
That may be the problem. Here is an example of
a scenario that works - without a hitch...

? dlookup("[vehiclejobid]","tblvehiclejobs","[ownerid]=2")
116

if dlookup("[vehiclejobid]","tblvehiclejobs","[ownerid]=2") then
msgbox "Hello"

Both of the above lines in the immediate window work as expected.
Of course, 116 evaluates to True a heck of a lot more reliably than
does "Acura". If you agree this is the root of my problem, pls let me
know you concur. Am tired of struggling with this.


Why not just test for Null?

If Not IsNull(dlookup("[vehiclejobid]","tblvehiclejobs","[ownerid]=2")) Then
MsgBox "Hello"

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #3

P: n/a
MLH
Believe me, I will from now on. Its much clearer.
Thx for the hint.

xxxxxxxxxxxxxxxxxxxxxxxxxxx

Why not just test for Null?

If Not IsNull(dlookup("[vehiclejobid]","tblvehiclejobs","[ownerid]=2")) Then
MsgBox "Hello"


Nov 13 '05 #4

P: n/a
Rick Brandt wrote:
"MLH" <CR**@NorthState.net> wrote in message
news:09********************************@4ax.com...
Is it because the DLookUp is returning a string???
A string cannot be evaluated as True or False.
That may be the problem. Here is an example of
a scenario that works - without a hitch...

? dlookup("[vehiclejobid]","tblvehiclejobs","[ownerid]=2")
116

if dlookup("[vehiclejobid]","tblvehiclejobs","[ownerid]=2") then
msgbox "Hello"

Both of the above lines in the immediate window work as expected.
Of course, 116 evaluates to True a heck of a lot more reliably than
does "Acura". If you agree this is the root of my problem, pls let me
know you concur. Am tired of struggling with this.

Why not just test for Null?

If Not IsNull(dlookup("[vehiclejobid]","tblvehiclejobs","[ownerid]=2")) Then
MsgBox "Hello"


Or use DCount() if checking for existence.

--
[OO=00=OO]
Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.