A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Problem(s) with DLookUp



 
 
Thread Tools Display Modes
  #1  
Old October 17th, 2009, 12:36 AM posted to microsoft.public.access.gettingstarted
BobC[_6_]
external usenet poster
 
Posts: 89
Default Problem(s) with DLookUp

I am having problems getting DLookUp to work when variables are
involved. The following expression works fine; until I try to
substitute the variable SVID in place of the number 332?

SiteID = DLookup("[ID]", "SiteTBL", "[Service Volume ID]=332")

SiteID is dimensioned as a Variant
[ID] and [Service Volume ID] is a number fields is SiteTBL table.

  #2  
Old October 17th, 2009, 12:53 AM posted to microsoft.public.access.gettingstarted
Jeff Boyce
external usenet poster
 
Posts: 8,621
Default Problem(s) with DLookUp

Bob

As you typed it, the DLookup() function is using the literal value of 332
for it's where clause.

I suspect your use of SVID as a direct replacement for 332 is causing Access
to try to find a [Service Volume ID] = , literally, SVID. Since [Service
Volume ID] is a number field, are you getting a 'type mismatch' error?

(check Access HELP for the syntax and examples using DLookup())

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or psuedocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.


"BobC" wrote in message
...
I am having problems getting DLookUp to work when variables are involved.
The following expression works fine; until I try to substitute the variable
SVID in place of the number 332?

SiteID = DLookup("[ID]", "SiteTBL", "[Service Volume ID]=332")

SiteID is dimensioned as a Variant
[ID] and [Service Volume ID] is a number fields is SiteTBL table.



  #4  
Old October 17th, 2009, 01:50 AM posted to microsoft.public.access.gettingstarted
BobC[_6_]
external usenet poster
 
Posts: 89
Default Problem(s) with DLookUp

No luck?
The examples I have found are also giving me problems ... maybe because
SVID is Dim As Integer?

Steve wrote:
Hello Bob!

Try this:

SiteID = DLookup("[ID]", "SiteTBL", "[Service Volume ID] = "& Me!SVID

Steve




wrote in message
...
I am having problems getting DLookUp to work when variables are involved.
The following expression works fine; until I try to substitute the variable
SVID in place of the number 332?

SiteID = DLookup("[ID]", "SiteTBL", "[Service Volume ID]=332")

SiteID is dimensioned as a Variant
[ID] and [Service Volume ID] is a number fields is SiteTBL table.



  #5  
Old October 17th, 2009, 11:26 AM posted to microsoft.public.access.gettingstarted
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Problem(s) with DLookUp

You mean SVID is simply a variable in your code, as opposed to a control on
your form?

SiteID = DLookup("[ID]", "SiteTBL", "[Service Volume ID] = "& SVID)

Note that this will only work if SiteID is defined as a Variant, since
DLookup will return Null if it cannot find a record corresponding to the
SVID value provided and Variants are the only data type that can hold Null
values. If you'd settle for having a SiteID of 0 if one isn't found, you
could declare SiteID as a specific type (Integer or Long), and then use

SiteID = Nz(DLookup("[ID]", "SiteTBL", "[Service Volume ID] = "& SVID), 0)


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"BobC" wrote in message
...
No luck?
The examples I have found are also giving me problems ... maybe because
SVID is Dim As Integer?

Steve wrote:
Hello Bob!

Try this:

SiteID = DLookup("[ID]", "SiteTBL", "[Service Volume ID] = "& Me!SVID

Steve




wrote in message
...
I am having problems getting DLookUp to work when variables are
involved.
The following expression works fine; until I try to substitute the
variable
SVID in place of the number 332?

SiteID = DLookup("[ID]", "SiteTBL", "[Service Volume ID]=332")

SiteID is dimensioned as a Variant
[ID] and [Service Volume ID] is a number fields is SiteTBL table.





  #6  
Old October 17th, 2009, 03:02 PM posted to microsoft.public.access.gettingstarted
BobC[_6_]
external usenet poster
 
Posts: 89
Default Problem(s) with DLookUp

Yes, SVID is a variable in my code.
In your example, does it matter if SVID is a Variant, Integer or String?

Douglas J. Steele wrote:
You mean SVID is simply a variable in your code, as opposed to a control on
your form?

SiteID = DLookup("[ID]", "SiteTBL", "[Service Volume ID] = "& SVID)

Note that this will only work if SiteID is defined as a Variant, since
DLookup will return Null if it cannot find a record corresponding to the
SVID value provided and Variants are the only data type that can hold Null
values. If you'd settle for having a SiteID of 0 if one isn't found, you
could declare SiteID as a specific type (Integer or Long), and then use

SiteID = Nz(DLookup("[ID]", "SiteTBL", "[Service Volume ID] = "& SVID), 0)


  #7  
Old October 17th, 2009, 08:06 PM posted to microsoft.public.access.gettingstarted
John Spencer
external usenet poster
 
Posts: 7,815
Default Problem(s) with DLookUp

Yes it does matter.

First I would probably declare SVID as a LONG and not an integer since the
largest integer is 64K in size.

If SVID is a variant then you could have a problem is you didn't populate it
with some value.

If SVID is a string then you should not have a problem (unless you fail to
assign it a value).

If Service Volume ID is a number then you have a valid statement.

If Service Volume ID is a string then you need to include quote marks around
the SVID when you use it in the expression.

SiteID = NZ(DLookup("[ID]", "SiteTBL", "[Service Volume ID] = """ & SVID &
""""),0)

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

BobC wrote:
Yes, SVID is a variable in my code.
In your example, does it matter if SVID is a Variant, Integer or String?

Douglas J. Steele wrote:
You mean SVID is simply a variable in your code, as opposed to a
control on
your form?

SiteID = DLookup("[ID]", "SiteTBL", "[Service Volume ID] = "& SVID)

Note that this will only work if SiteID is defined as a Variant, since
DLookup will return Null if it cannot find a record corresponding to the
SVID value provided and Variants are the only data type that can hold
Null
values. If you'd settle for having a SiteID of 0 if one isn't found, you
could declare SiteID as a specific type (Integer or Long), and then use

SiteID = Nz(DLookup("[ID]", "SiteTBL", "[Service Volume ID] = "&
SVID), 0)


  #8  
Old October 17th, 2009, 10:40 PM posted to microsoft.public.access.gettingstarted
BobC[_6_]
external usenet poster
 
Posts: 89
Default Problem(s) with DLookUp

John,
I certainly want to thank you for explaining it!
To date, I have been using 'trial and error(s!!!!!!!!!!!!!!!!!!)
Thanks Much!
Bob

John Spencer wrote:
Yes it does matter.

First I would probably declare SVID as a LONG and not an integer since
the largest integer is 64K in size.

If SVID is a variant then you could have a problem is you didn't
populate it with some value.

If SVID is a string then you should not have a problem (unless you fail
to assign it a value).

If Service Volume ID is a number then you have a valid statement.

If Service Volume ID is a string then you need to include quote marks
around the SVID when you use it in the expression.

SiteID = NZ(DLookup("[ID]", "SiteTBL", "[Service Volume ID] = """ & SVID
& """"),0)

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

BobC wrote:
Yes, SVID is a variable in my code.
In your example, does it matter if SVID is a Variant, Integer or String?

Douglas J. Steele wrote:
You mean SVID is simply a variable in your code, as opposed to a
control on
your form?

SiteID = DLookup("[ID]", "SiteTBL", "[Service Volume ID] = "& SVID)

Note that this will only work if SiteID is defined as a Variant, since
DLookup will return Null if it cannot find a record corresponding to the
SVID value provided and Variants are the only data type that can hold
Null
values. If you'd settle for having a SiteID of 0 if one isn't found, you
could declare SiteID as a specific type (Integer or Long), and then use

SiteID = Nz(DLookup("[ID]", "SiteTBL", "[Service Volume ID] = "&
SVID), 0)


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:41 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.