Dlookup returning a string instead of Integer

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

Guest

I have a Dlookup statement that is giving me string results but the field
from the table in which I am trying to pull data is of type Number (long
integer). For example I want it to return 100 instead of "100". Why is it
doing this??

Thanks,
Chace
 
It might depend on the context. For example, if this is an a query, and some
rows return Null, JET 4 is actually very poor at identifying the correct
data type. You need to explicitly typecast the results.

Since you cannot typecast a Null with the VBA functions, you will need
something like this:
CLng(Nz(DLookup("ID", "Table1"),0))

More info:
Calculated fields misinterpreted
at:
http://allenbrowne.com/ser-45.html

It's also interesting that previous version of JET (Access 97 and earlier)
did a better job of identifying data types than the current version does.
 
Worked like a champ!
Thanks,
Chace

Allen Browne said:
It might depend on the context. For example, if this is an a query, and some
rows return Null, JET 4 is actually very poor at identifying the correct
data type. You need to explicitly typecast the results.

Since you cannot typecast a Null with the VBA functions, you will need
something like this:
CLng(Nz(DLookup("ID", "Table1"),0))

More info:
Calculated fields misinterpreted
at:
http://allenbrowne.com/ser-45.html

It's also interesting that previous version of JET (Access 97 and earlier)
did a better job of identifying data types than the current version does.
 
Back
Top