473,511 Members | 10,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Having trouble with DLookUp in A97...

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
4 1839
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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
20745
by: KLAU | last post by:
I have a field that retrieves information from an expression in a query. I have used a DLookup function to get the calculated field from the query. However, the relationship is 1-to-many so one...
6
2325
by: JLM | last post by:
What am I missing here? I have a form where I enter a "Class Code". This value corresponds to what sits in table "class code descriptions" along with the "title" of each "class code." Key...
2
4128
by: ctyrrell | last post by:
I have read with interest the many discussions of the 3048 Error: Cannot open any more databases. I understand how the number of open Table ID's causes the problem. My question has to do with the...
8
4304
by: Christine Henderson | last post by:
I have a problem using the above function in the following simplified circumstance: In the lookup table called "Klms Travelled" I have 3 fields, eg: Receiver Name Receiver Suburb ...
11
2196
by: MLH | last post by:
DLookup("", "tblPreliminaryVINs", "=Forms!frmVINODO!SerialNum") is giving me a Type Mismatch error. That's confusing to me and I don't know how to circumvent it. The field in...
2
2266
by: Don | last post by:
Can someone help me fix my DLookup problem. I'm far from proficiency with Access. I've been creating databases for several years for work with the help of many of you and trial and error. I have...
3
1370
by: mindlike | last post by:
I have a form "DataEntry" with various fields "Ticker", "TickerName", etc. I want to autofill the "TickerName" field when I insert the Ticker in the "Ticker" field. So when I put IBM into the...
9
6610
by: | last post by:
In my database I have a 'control table' in which basic info is stored about the application, for instance the application's path and the name of the company that is using it. In all of the...
15
3088
by: rleepac | last post by:
This is a little complicated but I'll do my best to explain. In my db I have a table called L_AgeCorrection which has the following fields: Age, Sex, Frequency, AgeValue This is a table used to...
0
7245
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7144
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7427
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
5069
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1577
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
449
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.