Dlookup

E

Ernst Guckel

Hello,

I am having noting but problems with this... I cannot seem to figure out
why I am getting #Error

=DLookUp("[GenderDesc]","ltblGender","[GenderID] = " & [EmpGender])

=DLookUp("[W4StatusDesc]","ltblW4Status","[W4StatusID] = " & [EmpW4Status])

both return #Error but if I enter the same thing in VBA I get the right
answer...

Ernst.
 
F

fredg

Hello,

I am having noting but problems with this... I cannot seem to figure out
why I am getting #Error

=DLookUp("[GenderDesc]","ltblGender","[GenderID] = " & [EmpGender])

=DLookUp("[W4StatusDesc]","ltblW4Status","[W4StatusID] = " & [EmpW4Status])

both return #Error but if I enter the same thing in VBA I get the right
answer...

Ernst.

Make sure the name of control (in the report) is NOT the same as the
name of any field used in the control source expression.
 
A

Allen Browne

In ltblGender, is GenderID a Number field or a Text field?

If it's Text, you need extra quotes:
=DLookUp("[GenderDesc]", "ltblGender",
"[GenderID] = """ & [EmpGender] & """")
For an explanation, see:
http://allenbrowne.com/casu-17.html

If it is a Number field you would an error if EmpGender is null, since the
3rd argument would end up being just:
[GenderID] =
which is clearly wrong. To fix this error, use Nz() to supply something for
null, e.g.:
=DLookUp("[GenderDesc]", "ltblGender",
"[GenderID] = " & Nz([EmpGender],0))

Whatever EmpGender is, of couse its value has to match the same data type as
the field in the table.
 
E

Ernst Guckel

Still having the same problem. I have since renamed the control to something
other than the field name (Didn't catch that) but it still returns the same
error...

txtGenderID returns 1 < -- [EmpGender] <-- field name
txtGender with the lookup returns #Error but it should return "Male"


Ernst.

Allen Browne said:
In ltblGender, is GenderID a Number field or a Text field?

If it's Text, you need extra quotes:
=DLookUp("[GenderDesc]", "ltblGender",
"[GenderID] = """ & [EmpGender] & """")
For an explanation, see:
http://allenbrowne.com/casu-17.html

If it is a Number field you would an error if EmpGender is null, since the
3rd argument would end up being just:
[GenderID] =
which is clearly wrong. To fix this error, use Nz() to supply something for
null, e.g.:
=DLookUp("[GenderDesc]", "ltblGender",
"[GenderID] = " & Nz([EmpGender],0))

Whatever EmpGender is, of couse its value has to match the same data type as
the field in the table.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Ernst Guckel said:
Hello,

I am having noting but problems with this... I cannot seem to figure out
why I am getting #Error

=DLookUp("[GenderDesc]","ltblGender","[GenderID] = " & [EmpGender])

=DLookUp("[W4StatusDesc]","ltblW4Status","[W4StatusID] = " &
[EmpW4Status])

both return #Error but if I enter the same thing in VBA I get the right
answer...

Ernst.
 
A

Allen Browne

Press Ctrl+G to open the Immediate Window.

Work there to build up the expression until you get it right.

Start with:
? DLookUp("GenderDesc", "ltblGender")
That should return a value (though you have not specified which one.)

Then build up the 3rd argument, watching the data types as explained.

If you need more help, see:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html

Once you get it right in the Immediate Window, you can then work on getting
it right in the report.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Ernst Guckel said:
Still having the same problem. I have since renamed the control to
something
other than the field name (Didn't catch that) but it still returns the
same
error...

txtGenderID returns 1 < -- [EmpGender] <-- field name
txtGender with the lookup returns #Error but it should return "Male"


Ernst.

Allen Browne said:
In ltblGender, is GenderID a Number field or a Text field?

If it's Text, you need extra quotes:
=DLookUp("[GenderDesc]", "ltblGender",
"[GenderID] = """ & [EmpGender] & """")
For an explanation, see:
http://allenbrowne.com/casu-17.html

If it is a Number field you would an error if EmpGender is null, since
the
3rd argument would end up being just:
[GenderID] =
which is clearly wrong. To fix this error, use Nz() to supply something
for
null, e.g.:
=DLookUp("[GenderDesc]", "ltblGender",
"[GenderID] = " & Nz([EmpGender],0))

Whatever EmpGender is, of couse its value has to match the same data type
as
the field in the table.

Ernst Guckel said:
Hello,

I am having noting but problems with this... I cannot seem to figure
out
why I am getting #Error

=DLookUp("[GenderDesc]","ltblGender","[GenderID] = " & [EmpGender])

=DLookUp("[W4StatusDesc]","ltblW4Status","[W4StatusID] = " &
[EmpW4Status])

both return #Error but if I enter the same thing in VBA I get the
right
answer...
 
E

Ernst Guckel

Thanks... got it.

Ernst.

Allen Browne said:
Press Ctrl+G to open the Immediate Window.

Work there to build up the expression until you get it right.

Start with:
? DLookUp("GenderDesc", "ltblGender")
That should return a value (though you have not specified which one.)

Then build up the 3rd argument, watching the data types as explained.

If you need more help, see:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html

Once you get it right in the Immediate Window, you can then work on getting
it right in the report.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Ernst Guckel said:
Still having the same problem. I have since renamed the control to
something
other than the field name (Didn't catch that) but it still returns the
same
error...

txtGenderID returns 1 < -- [EmpGender] <-- field name
txtGender with the lookup returns #Error but it should return "Male"


Ernst.

Allen Browne said:
In ltblGender, is GenderID a Number field or a Text field?

If it's Text, you need extra quotes:
=DLookUp("[GenderDesc]", "ltblGender",
"[GenderID] = """ & [EmpGender] & """")
For an explanation, see:
http://allenbrowne.com/casu-17.html

If it is a Number field you would an error if EmpGender is null, since
the
3rd argument would end up being just:
[GenderID] =
which is clearly wrong. To fix this error, use Nz() to supply something
for
null, e.g.:
=DLookUp("[GenderDesc]", "ltblGender",
"[GenderID] = " & Nz([EmpGender],0))

Whatever EmpGender is, of couse its value has to match the same data type
as
the field in the table.

Hello,

I am having noting but problems with this... I cannot seem to figure
out
why I am getting #Error

=DLookUp("[GenderDesc]","ltblGender","[GenderID] = " & [EmpGender])

=DLookUp("[W4StatusDesc]","ltblW4Status","[W4StatusID] = " &
[EmpW4Status])

both return #Error but if I enter the same thing in VBA I get the
right
answer...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Dlookup in Detail 7
Access ACCESS DLOOKUP INVALID USE OF NULL 0
Help with IIF / DLookup formula 6
dlookup based on first digits of a field 3
DLookup in a grouped footer 4
dlookup error 2001 1
DLookUp problem 1
DlookUp 7

Top