Dlookup not working

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dim EmailAll As Variant
Thanks in advance:

I have this script iin a button

EmailAll = DLookup("[DistListName]", "LocationName", "[LocID] = 1")

Table: LocationName
Field : DistListName in Table LocationName
Filed: LocID in Table LocationName

I keep getting "Empty" when I run the script? Any ideas why this is
working. I only have one record in the table and I can't get it to work.
Does Dlookup only work with certain references. I have tried leaving off the
criteria, still nothing. HELP!
 
Is [LocID] a numeric field? If not, change your last argument to "[LocID] =
'1'"
Other than that, your code looks fine. The empty you are getting is
probably because if the DLookup doesn't find a match, it returns Null.
EmailAll will then be Null and can evaluate to Empty depending on how you are
using it.
 
But there is something in the field, why does it not return the value?

Klatuu said:
Is [LocID] a numeric field? If not, change your last argument to "[LocID] =
'1'"
Other than that, your code looks fine. The empty you are getting is
probably because if the DLookup doesn't find a match, it returns Null.
EmailAll will then be Null and can evaluate to Empty depending on how you are
using it.

MoonBlosm said:
Dim EmailAll As Variant
Thanks in advance:

I have this script iin a button

EmailAll = DLookup("[DistListName]", "LocationName", "[LocID] = 1")

Table: LocationName
Field : DistListName in Table LocationName
Filed: LocID in Table LocationName

I keep getting "Empty" when I run the script? Any ideas why this is
working. I only have one record in the table and I can't get it to work.
Does Dlookup only work with certain references. I have tried leaving off the
criteria, still nothing. HELP!
 
Reread my last post. the syntax is different for numeric and text fields.
Also, are you sure it is exactly a 1 in the field. If it is a text field,
there may be a space or other unprintable character in the field with it.
Open the table, retrieve the field into a variable, then examine it to
determine exactly what it is.

MoonBlosm said:
But there is something in the field, why does it not return the value?

Klatuu said:
Is [LocID] a numeric field? If not, change your last argument to "[LocID] =
'1'"
Other than that, your code looks fine. The empty you are getting is
probably because if the DLookup doesn't find a match, it returns Null.
EmailAll will then be Null and can evaluate to Empty depending on how you are
using it.

MoonBlosm said:
Dim EmailAll As Variant
Thanks in advance:

I have this script iin a button

EmailAll = DLookup("[DistListName]", "LocationName", "[LocID] = 1")

Table: LocationName
Field : DistListName in Table LocationName
Filed: LocID in Table LocationName

I keep getting "Empty" when I run the script? Any ideas why this is
working. I only have one record in the table and I can't get it to work.
Does Dlookup only work with certain references. I have tried leaving off the
criteria, still nothing. HELP!
 
Thanks for all your help, but it is a numeric field and it is just the number
one.

Klatuu said:
Reread my last post. the syntax is different for numeric and text fields.
Also, are you sure it is exactly a 1 in the field. If it is a text field,
there may be a space or other unprintable character in the field with it.
Open the table, retrieve the field into a variable, then examine it to
determine exactly what it is.

MoonBlosm said:
But there is something in the field, why does it not return the value?

Klatuu said:
Is [LocID] a numeric field? If not, change your last argument to "[LocID] =
'1'"
Other than that, your code looks fine. The empty you are getting is
probably because if the DLookup doesn't find a match, it returns Null.
EmailAll will then be Null and can evaluate to Empty depending on how you are
using it.

:

Dim EmailAll As Variant
Thanks in advance:

I have this script iin a button

EmailAll = DLookup("[DistListName]", "LocationName", "[LocID] = 1")

Table: LocationName
Field : DistListName in Table LocationName
Filed: LocID in Table LocationName

I keep getting "Empty" when I run the script? Any ideas why this is
working. I only have one record in the table and I can't get it to work.
Does Dlookup only work with certain references. I have tried leaving off the
criteria, still nothing. HELP!
 
Okay, when are you getting the error? Have you run your code in debug mode
stepping through one line at a time to see what is happening. It could be
the DLookup is not the problem. Your code is correct.

MoonBlosm said:
Thanks for all your help, but it is a numeric field and it is just the number
one.

Klatuu said:
Reread my last post. the syntax is different for numeric and text fields.
Also, are you sure it is exactly a 1 in the field. If it is a text field,
there may be a space or other unprintable character in the field with it.
Open the table, retrieve the field into a variable, then examine it to
determine exactly what it is.

MoonBlosm said:
But there is something in the field, why does it not return the value?

:

Is [LocID] a numeric field? If not, change your last argument to "[LocID] =
'1'"
Other than that, your code looks fine. The empty you are getting is
probably because if the DLookup doesn't find a match, it returns Null.
EmailAll will then be Null and can evaluate to Empty depending on how you are
using it.

:

Dim EmailAll As Variant
Thanks in advance:

I have this script iin a button

EmailAll = DLookup("[DistListName]", "LocationName", "[LocID] = 1")

Table: LocationName
Field : DistListName in Table LocationName
Filed: LocID in Table LocationName

I keep getting "Empty" when I run the script? Any ideas why this is
working. I only have one record in the table and I can't get it to work.
Does Dlookup only work with certain references. I have tried leaving off the
criteria, still nothing. HELP!
 
Yes I have stepped through, and it really isnt giving me an error, just
giving me nothing. It is like there is nothing in the field. The field it
is grabbing is a text field. I have tried addind another record. The LocID
has been changed to an auto number even. I have tried all different
variations and feel like banging my head on the keyboard because I am sure
the code is right... but I can not figure out why it won't pull the info. I
have tried with different tables and can't get anything to pull. The code is
on a button on a form. I was just wondering if a certain reference needs to
be used to make it work.


This is the fields and what is located in the field
LocID DistListName Location
1 VITAHamptonRoads Hampton Roads

Klatuu said:
Okay, when are you getting the error? Have you run your code in debug mode
stepping through one line at a time to see what is happening. It could be
the DLookup is not the problem. Your code is correct.

MoonBlosm said:
Thanks for all your help, but it is a numeric field and it is just the number
one.

Klatuu said:
Reread my last post. the syntax is different for numeric and text fields.
Also, are you sure it is exactly a 1 in the field. If it is a text field,
there may be a space or other unprintable character in the field with it.
Open the table, retrieve the field into a variable, then examine it to
determine exactly what it is.

:

But there is something in the field, why does it not return the value?

:

Is [LocID] a numeric field? If not, change your last argument to "[LocID] =
'1'"
Other than that, your code looks fine. The empty you are getting is
probably because if the DLookup doesn't find a match, it returns Null.
EmailAll will then be Null and can evaluate to Empty depending on how you are
using it.

:

Dim EmailAll As Variant
Thanks in advance:

I have this script iin a button

EmailAll = DLookup("[DistListName]", "LocationName", "[LocID] = 1")

Table: LocationName
Field : DistListName in Table LocationName
Filed: LocID in Table LocationName

I keep getting "Empty" when I run the script? Any ideas why this is
working. I only have one record in the table and I can't get it to work.
Does Dlookup only work with certain references. I have tried leaving off the
criteria, still nothing. HELP!
 
Everything looks correct. I don't get it. What happens if you enter the
Dlookup code in the immediate window?

MoonBlosm said:
Yes I have stepped through, and it really isnt giving me an error, just
giving me nothing. It is like there is nothing in the field. The field it
is grabbing is a text field. I have tried addind another record. The LocID
has been changed to an auto number even. I have tried all different
variations and feel like banging my head on the keyboard because I am sure
the code is right... but I can not figure out why it won't pull the info. I
have tried with different tables and can't get anything to pull. The code is
on a button on a form. I was just wondering if a certain reference needs to
be used to make it work.


This is the fields and what is located in the field
LocID DistListName Location
1 VITAHamptonRoads Hampton Roads

Klatuu said:
Okay, when are you getting the error? Have you run your code in debug mode
stepping through one line at a time to see what is happening. It could be
the DLookup is not the problem. Your code is correct.

MoonBlosm said:
Thanks for all your help, but it is a numeric field and it is just the number
one.

:

Reread my last post. the syntax is different for numeric and text fields.
Also, are you sure it is exactly a 1 in the field. If it is a text field,
there may be a space or other unprintable character in the field with it.
Open the table, retrieve the field into a variable, then examine it to
determine exactly what it is.

:

But there is something in the field, why does it not return the value?

:

Is [LocID] a numeric field? If not, change your last argument to "[LocID] =
'1'"
Other than that, your code looks fine. The empty you are getting is
probably because if the DLookup doesn't find a match, it returns Null.
EmailAll will then be Null and can evaluate to Empty depending on how you are
using it.

:

Dim EmailAll As Variant
Thanks in advance:

I have this script iin a button

EmailAll = DLookup("[DistListName]", "LocationName", "[LocID] = 1")

Table: LocationName
Field : DistListName in Table LocationName
Filed: LocID in Table LocationName

I keep getting "Empty" when I run the script? Any ideas why this is
working. I only have one record in the table and I can't get it to work.
Does Dlookup only work with certain references. I have tried leaving off the
criteria, still nothing. HELP!
 
I can't see anything wrong either. I'm curious, when you say it is giving
you nothing, exactly what do you mean? How/where are you using the variable
EmailAll? Have you tried something like this?

EmailAll = DLookup("[DistListName]", "LocationName", "[LocID] = 1")
debug.print emailAll

Then examine the immediate window.

Please post the full code and show where you are trying to use the
variable - maybe that'll shed some light on the problem.

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Yes I have stepped through, and it really isnt giving me an error,
just giving me nothing. It is like there is nothing in the field.
The field it is grabbing is a text field. I have tried addind
another record. The LocID has been changed to an auto number even.
I have tried all different variations and feel like banging my head
on the keyboard because I am sure the code is right... but I can not
figure out why it won't pull the info. I have tried with different
tables and can't get anything to pull. The code is on a button on a
form. I was just wondering if a certain reference needs to be used
to make it work.


This is the fields and what is located in the field
LocID DistListName Location
1 VITAHamptonRoads Hampton Roads

Klatuu said:
Okay, when are you getting the error? Have you run your code in
debug mode stepping through one line at a time to see what is
happening. It could be the DLookup is not the problem. Your code
is correct.

MoonBlosm said:
Thanks for all your help, but it is a numeric field and it is just
the number one.

:

Reread my last post. the syntax is different for numeric and text
fields. Also, are you sure it is exactly a 1 in the field. If it
is a text field, there may be a space or other unprintable
character in the field with it. Open the table, retrieve the field
into a variable, then examine it to determine exactly what it is.

:

But there is something in the field, why does it not return the
value?

:

Is [LocID] a numeric field? If not, change your last argument
to "[LocID] = '1'"
Other than that, your code looks fine. The empty you are
getting is probably because if the DLookup doesn't find a match,
it returns Null. EmailAll will then be Null and can evaluate to
Empty depending on how you are using it.

:

Dim EmailAll As Variant
Thanks in advance:

I have this script iin a button

EmailAll = DLookup("[DistListName]", "LocationName", "[LocID] =
1")

Table: LocationName
Field : DistListName in Table LocationName
Filed: LocID in Table LocationName

I keep getting "Empty" when I run the script? Any ideas why
this is working. I only have one record in the table and I
can't get it to work. Does Dlookup only work with certain
references. I have tried leaving off the criteria, still
nothing. HELP!
 
If this is VBA then try removing the square brackets around DistListName and
LocID. Also check that LocID is a number type field.
 
The square brackets are fine.

Are you sure that LocID is equal to 1?

In general, since DLookup will return a Null value when the record isn't
found, you should probably use the Nz function in conjunction with it:

EmailAll = Nz(DLookup("[DistListName]", "LocationName", "[LocID] = 1"), "Not
Found")


If there's only one record, though, you can simply use

EmailAll = DLookup("[DistListName]", "LocationName")


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


AlienzDDS said:
If this is VBA then try removing the square brackets around DistListName
and
LocID. Also check that LocID is a number type field.

MoonBlosm said:
Dim EmailAll As Variant
Thanks in advance:

I have this script iin a button

EmailAll = DLookup("[DistListName]", "LocationName", "[LocID] = 1")

Table: LocationName
Field : DistListName in Table LocationName
Filed: LocID in Table LocationName

I keep getting "Empty" when I run the script? Any ideas why this is
working. I only have one record in the table and I can't get it to work.
Does Dlookup only work with certain references. I have tried leaving off
the
criteria, still nothing. HELP!
 
Back
Top