Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    zkrucz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    103

    Question Invalid Syntax or Operand without an Operator in a Query

    Intent: I want to confirm that Operand 1 has the value of “Copper/Plastic” AND Operand 2 has the value of either 1 or 2, and then return the value of the Operand 2 (values of either 1 or 2), otherwise return a null value.


    1. 57 is the field for Inventory number
    2. Operand 1: [Horn Adapter Make:]
    3. Operand 2: [Horn Adapter 1/2-in Qty:]


    57: IIf(([Horn Adapter Make:]="Copper/Plastic") AND ([Horn Adapter 1/2-in Qty:]="1" AND ([Horn Adapter 1/2-in Qty:]="2"),"[Horn Adapter 1/2-in Qty:]"," ")

    With the operation above, I get the following error message:
    “the expression you entered contains invalid syntax.
    You may have entered an operand without an operator”

    What am I doing wrong?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    Numbers do not usu have strings around them.
    If the field QTY is in fact a number you will get errors trying to ask for a # inside quotes: [Horn Adapter 1/2-in Qty:]="2"

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    57: IIf(([Horn Adapter Make:]="Copper/Plastic") AND ([Horn Adapter 1/2-in Qty:]=1 OR ([Horn Adapter 1/2-in Qty:]=2),"[Horn Adapter 1/2-in Qty:]"," ")

    In addition to Ranman suggestion, the qty can't be 1 and 2 at the same time...

  4. #4
    zkrucz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    103
    @ Ranman
    @ davergi
    OK, I tried this (I corrected to include a parentheses after And ([Horn Adapter 1/2-in Qty:]=1) (as below)

    However, the Query returns the value of #Error. Is this because I have the values of 1 and 2? Can I get around this by changing the input values from 1 to one and from 2 to two?

    57: IIf(([Horn Adapter Make:]="Copper/Plastic") And ([Horn Adapter 1/2-in Qty:]=1) Or ([Horn Adapter 1/2-in Qty:]=2),"[Horn Adapter 1/2-in Qty:]"," ")

  5. #5
    zkrucz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    103
    @ Ranman
    @ davergi


    OK, I modified to reflect the words one and two.And it does work! the operatioon returns one and two, where appropriate.

    However, I would really like to have the returned values as numeric values so that I can use outside of Access to tabulate the actual quantities?

    57: IIf(([Horn Adapter Make:]="Copper/Plastic") And ([Horn Adapter 1/2-in Qty:]="one") Or ([Horn Adapter 1/2-in Qty:]="two"),[Horn Adapter 1/2-in Qty:]," ")

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    "[Horn Adapter 1/2-in Qty:]"," "
    If the first part of the IIF expression returns True, then you want the expression to return a number, but if False, then return an empty string? It could be that you're trying to place string type data where only a number can go.

    "[Horn Adapter 1/2-in Qty:]"
    I think there should be no quotes around the reference to the field (as there are not in the first part).

    Also, you might want to explore your bracketing; thinking that the OR comparison should take place 1st, and as noted, perhaps not to use a string if a number is required for the field.
    IIf(([Horn Adapter Make:]="Copper/Plastic" And (([Horn Adapter 1/2-in Qty:]=1 Or [Horn Adapter 1/2-in Qty:]=2))),"[Horn Adapter 1/2-in Qty:]",0)

    I would try the number thing first.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    zkrucz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    103
    @ Ranman
    @ davergi

    SUCCESS! I tried the modified version (below) and it returns the numeric values that I was looking for.

    Thank you so much for your help.

    57: IIf(([Horn Adapter Make:]="Copper/Plastic") And ([Horn Adapter 1/2-in Qty:]="1") Or ([Horn Adapter 1/2-in Qty:]="2"),[Horn Adapter 1/2-in Qty:]," ")

  8. #8
    zkrucz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    103
    @ Ranman
    @ davergi
    @ Micron


    OK, I played with Micron's suggestion and tweaked it a bit. And, it does (as above) return the numeric values of 1 or 2 (where appropriate). Success again!

    Thank you so much.

    57: IIf(([Horn Adapter Make:]="Copper/Plastic" And (([Horn Adapter 1/2-in Qty:]="1" Or [Horn Adapter 1/2-in Qty:]="2"))),[Horn Adapter 1/2-in Qty:]," ")

  9. #9
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    Just as an aside, I would avoid calling an alias anything numeric - access doesn't like numbers at the start of fields, and if you ever up-size I don't think SQL allows it.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  10. #10
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I agree with Minty about the naming of objects.

    Here are some Naming suggestions:
    Use only letters and numbers (exception is the underscore) for object names.
    Do not use spaces, punctuation or special characters in object names.
    Do not begin object names with a number. (the Access gnomes can get persnickety and cause intermittent problems)

    Also
    Do not use look up FIELDS, multi-value fields or calculated fields in tables.


    And talking about naming....... your field names are terrible! Not flaming you, just sayin.

    BAD
    Better Option1
    Better Option 2
    [Horn Adapter Make:] HornAdapterMake HornAdapterMake
    [Horn Adapter 1/2-in Qty:] HornAdapter_1_2InQty HornAdapterQty

    If you have the size of something in the field name (ie 1/2 in, 3/4 in), you end up with a non-normalized structure.
    The size is data and shouldn't be in the field name.

  11. #11
    zkrucz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    103
    @ssanfu

    I do appreciate your comments. And, I will incorporate in the future.
    But to explain the current situation.
    I inherited the field names which come from a questionnaire filled out by techs on their tablets. These "questions" correspond to field names in the database. The "questions" drive the DB field names as they are meant to not confuse the techs with "efficient' DB format but rather use everyday English fromat.

    However, I can see that while in the process of importation, these "questions" can be substituted with corresponding field name aliases which do meet the efficient DB format.

    Thank you for your comments and useful observations.

  12. #12
    ArnieT is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    10
    Could you please elaborate on your suggestion not to use lookup fields in tables? How do I automate entering data into this field from a finite list? Or am I guessing right that tables should not be used for entering data, but only for storing them, and use forms for entering data?

  13. #13
    Join Date
    Apr 2017
    Posts
    1,673
    Quote Originally Posted by ArnieT View Post
    Or am I guessing right that tables should not be used for entering data, but only for storing them, and use forms for entering data?
    You are quessing right!

  14. #14
    ArnieT is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    10
    Quote Originally Posted by ArviLaanemets View Post
    You are quessing right!
    In that case, will you be able to suggest how to limit the lookup list in a form field based on a criterion in another field?
    Here is more expanded description of the question, although for tables. But, I think, the general idea is still the same.
    https://www.accessforums.net/showthread.php?t=70759

    As an aside, I have always constructed tables first and then fitted forms to them.
    Last edited by ArnieT; 02-25-2018 at 09:44 AM. Reason: wrong URL

  15. #15
    Join Date
    Apr 2017
    Posts
    1,673
    In general, AfterUpdate event of first control (NB! You have to differ between fields, which are table things, and controls, which are elements of form. Controls have a table field as source, or they have an expression instead.) rewrites the Row Source of another combo box/list box. And of course, an OnCurrent event of form rewrites also the Row source of second combo box whenever another record is activated. There were sevaral postings about this in last couple of months - look for cascading controls/combo boxes/whatever.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Operand without an operator error
    By mdnikki in forum Queries
    Replies: 4
    Last Post: 08-28-2017, 02:33 PM
  2. Operand without an operator error
    By Thompyt in forum Programming
    Replies: 3
    Last Post: 04-15-2015, 04:38 PM
  3. Replies: 5
    Last Post: 07-22-2014, 06:58 AM
  4. Operand without operator or
    By burrina in forum Queries
    Replies: 2
    Last Post: 12-31-2012, 06:14 PM
  5. Replies: 7
    Last Post: 08-28-2011, 02:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums