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 » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Syntax error in DLookup expression



 
 
Thread Tools Display Modes
  #1  
Old January 4th, 2010, 11:02 PM posted to microsoft.public.access.forms
Pamela
external usenet poster
 
Posts: 193
Default Syntax error in DLookup expression

I am getting a syntax error that there's a missing operator in query
expression 'ShopID ='. From this it almost seems that it isn't reading the
True statement in our expression which should disregard that "false" part of
the expression altogether. Any ideas how to fix this? Here's the expression:
IIf(IsNull(Me.ShopName), "The owner has not yet chosen a repair shop.", _
DLookup("Expr1", "qryShopReturn", "ShopID = " & Me!ShopName) & " ").
ShopName is a cbo that is populated by tblShop where ShopID is bound but
ShopName is displayed. Thanks for your help!
Pamela
  #2  
Old January 4th, 2010, 11:32 PM posted to microsoft.public.access.forms
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Syntax error in DLookup expression

You need to tie all the separate pieces of advice you've been getting
together. (This is best accomplished by continuing to post in the same
thread, rather than constantly starting new one!)

Is ShopID text? If so, you need

DLookup("Expr1", "qryShopReturn", "ShopID = '" & Me!ShopName & "'")

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


"Pamela" wrote in message
...
I am getting a syntax error that there's a missing operator in query
expression 'ShopID ='. From this it almost seems that it isn't reading
the
True statement in our expression which should disregard that "false" part
of
the expression altogether. Any ideas how to fix this? Here's the
expression:
IIf(IsNull(Me.ShopName), "The owner has not yet chosen a repair shop.", _
DLookup("Expr1", "qryShopReturn", "ShopID = " & Me!ShopName) & " ").
ShopName is a cbo that is populated by tblShop where ShopID is bound but
ShopName is displayed. Thanks for your help!
Pamela



  #3  
Old January 4th, 2010, 11:57 PM posted to microsoft.public.access.forms
Beetle
external usenet poster
 
Posts: 1,254
Default Syntax error in DLookup expression

What is the data type of ShopID in tblShop
(i.e. number, text)?
--
_________

Sean Bailey


"Pamela" wrote:

I am getting a syntax error that there's a missing operator in query
expression 'ShopID ='. From this it almost seems that it isn't reading the
True statement in our expression which should disregard that "false" part of
the expression altogether. Any ideas how to fix this? Here's the expression:
IIf(IsNull(Me.ShopName), "The owner has not yet chosen a repair shop.", _
DLookup("Expr1", "qryShopReturn", "ShopID = " & Me!ShopName) & " ").
ShopName is a cbo that is populated by tblShop where ShopID is bound but
ShopName is displayed. Thanks for your help!
Pamela

  #4  
Old January 5th, 2010, 12:01 AM posted to microsoft.public.access.forms
Pamela
external usenet poster
 
Posts: 193
Default Syntax error in DLookup expression

ShopID is AutoNumber (pk). I hope this helps you help me! : ) Thanks!

"Beetle" wrote:

What is the data type of ShopID in tblShop
(i.e. number, text)?
--
_________

Sean Bailey


"Pamela" wrote:

I am getting a syntax error that there's a missing operator in query
expression 'ShopID ='. From this it almost seems that it isn't reading the
True statement in our expression which should disregard that "false" part of
the expression altogether. Any ideas how to fix this? Here's the expression:
IIf(IsNull(Me.ShopName), "The owner has not yet chosen a repair shop.", _
DLookup("Expr1", "qryShopReturn", "ShopID = " & Me!ShopName) & " ").
ShopName is a cbo that is populated by tblShop where ShopID is bound but
ShopName is displayed. Thanks for your help!
Pamela

  #5  
Old January 5th, 2010, 12:27 AM posted to microsoft.public.access.forms
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Syntax error in DLookup expression

On Mon, 4 Jan 2010 14:02:01 -0800, Pamela
wrote:

I am getting a syntax error that there's a missing operator in query
expression 'ShopID ='. From this it almost seems that it isn't reading the
True statement in our expression which should disregard that "false" part of
the expression altogether. Any ideas how to fix this? Here's the expression:
IIf(IsNull(Me.ShopName), "The owner has not yet chosen a repair shop.", _
DLookup("Expr1", "qryShopReturn", "ShopID = " & Me!ShopName) & " ").
ShopName is a cbo that is populated by tblShop where ShopID is bound but
ShopName is displayed. Thanks for your help!
Pamela


The problem is that the IIF statement (sometimes, not always!) evaluates both
the True and False branches. Try a different approach like

IIf(IsNull(Me.ShopName), "The owner has not yet chosen a repair shop.",
DLookup("Expr1", "qryShopReturn", "ShopID = " & NZ(Me!ShopName))

If there is nothing selected in the combo box ShopName this will return NULL
from the DLookUp (actually it will return the shopname for ShopID equal to 0,
which I assume does not exist).
--

John W. Vinson [MVP]
  #6  
Old January 5th, 2010, 01:08 AM posted to microsoft.public.access.forms
Jeff Boyce
external usenet poster
 
Posts: 8,621
Default Syntax error in DLookup expression

Pamela

Why are you trying to lookup something when the ShopID = (something that
seems like it would be text -- ShopName)?

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 pseudocode 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.


"Pamela" wrote in message
...
ShopID is AutoNumber (pk). I hope this helps you help me! : ) Thanks!

"Beetle" wrote:

What is the data type of ShopID in tblShop
(i.e. number, text)?
--
_________

Sean Bailey


"Pamela" wrote:

I am getting a syntax error that there's a missing operator in query
expression 'ShopID ='. From this it almost seems that it isn't
reading the
True statement in our expression which should disregard that "false"
part of
the expression altogether. Any ideas how to fix this? Here's the
expression:
IIf(IsNull(Me.ShopName), "The owner has not yet chosen a repair shop.",
_
DLookup("Expr1", "qryShopReturn", "ShopID = " & Me!ShopName) & " ").
ShopName is a cbo that is populated by tblShop where ShopID is bound
but
ShopName is displayed. Thanks for your help!
Pamela



  #7  
Old January 5th, 2010, 03:00 AM posted to microsoft.public.access.forms
Pamela
external usenet poster
 
Posts: 193
Default Syntax error in DLookup expression

Thanks, John! The system didn't like that expression in there either. But,
I figured another way to do it using my query: I wrote the expression in my
query, added and joined my form's underlying table to ltblShop and used
AssnNumber as the Lookup which is has a one-to-one relationsthip with all of
my forms/subforms.

Thanks!!!

"John W. Vinson" wrote:

On Mon, 4 Jan 2010 14:02:01 -0800, Pamela
wrote:

I am getting a syntax error that there's a missing operator in query
expression 'ShopID ='. From this it almost seems that it isn't reading the
True statement in our expression which should disregard that "false" part of
the expression altogether. Any ideas how to fix this? Here's the expression:
IIf(IsNull(Me.ShopName), "The owner has not yet chosen a repair shop.", _
DLookup("Expr1", "qryShopReturn", "ShopID = " & Me!ShopName) & " ").
ShopName is a cbo that is populated by tblShop where ShopID is bound but
ShopName is displayed. Thanks for your help!
Pamela


The problem is that the IIF statement (sometimes, not always!) evaluates both
the True and False branches. Try a different approach like

IIf(IsNull(Me.ShopName), "The owner has not yet chosen a repair shop.",
DLookup("Expr1", "qryShopReturn", "ShopID = " & NZ(Me!ShopName))

If there is nothing selected in the combo box ShopName this will return NULL
from the DLookUp (actually it will return the shopname for ShopID equal to 0,
which I assume does not exist).
--

John W. Vinson [MVP]
.

 




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 06:55 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.