Results 1 to 4 of 4
  1. #1
    BigCat's Avatar
    BigCat is offline Vice Pres. of Napping
    Windows XP Access 2007
    Join Date
    May 2011
    Location
    Box Canyon
    Posts
    52

    Question IIF Not Fully Working. Please Help!

    Right now I am trying to take a couple fields from one of my tables and then use an IIF statement to fill some data into a third empty field, but right now when I run it all it just puts the entire IIF Statement into that third field.



    [PROD LINE] : iif([LONG MODEL]="LT*" OR "LD*" OR "ST*", "REFUSE", "")

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    Well the syntax is wrong. What exactly do you want?

    Syntax wise you would need something like this

    [PROD LINE] : iif([LONG MODEL]="LT*" OR [LONG MODEL]= "LD*" OR [LONG MODEL]= "ST*", "REFUSE", "")

    The asterisk has a special meaning in Access under
    some conditions. Usually you would use an asterisk * when you are looking for
    any character. Like "c*" to get to "cow", "cat","candle"

    Do you really have an * in the field? Could [Long Model] actually have the value "LT*"?

  3. #3
    BigCat's Avatar
    BigCat is offline Vice Pres. of Napping
    Windows XP Access 2007
    Join Date
    May 2011
    Location
    Box Canyon
    Posts
    52
    The LONG MODEL field has different truck model numbers and I am trying to put into the database what type of truck it is and that is determined by the first two letters, so that is why I wanted to use the * so it didn't matter what the rest was it would only look at the first two characters.

    I just copied and pasted in what you said but it keeps just throwing the entire IIF statement code into my PROD LINE field and for some reason it changes all of my "" into []
    Last edited by BigCat; 05-20-2011 at 08:12 AM. Reason: adding additional info

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    A couple of points and you've probably heard these before.

    Field names with embedded spaces and/or special characters will come back to bite you.
    If you have the option, get rid of them.

    Instead of this
    [PROD LINE] : iif([LONG MODEL]="LT*" OR [LONG MODEL]= "LD*" OR [LONG MODEL]= "ST*", "REFUSE", "")
    Try
    [PROD LINE] : iif(Left([LONG MODEL],2)="LT" _
    OR Left([LONG MODEL],2)= "LD" _
    OR Left([LONG MODEL],2)= "ST", "REFUSE", "")

    This will compare the 2 leftmost characters...

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Working with TableDefs
    By farssr in forum Programming
    Replies: 2
    Last Post: 03-14-2011, 07:17 PM
  2. VBA Code Not working
    By jo15765 in forum Programming
    Replies: 12
    Last Post: 12-03-2010, 04:01 PM
  3. Grouping not working
    By jgelpi16 in forum Reports
    Replies: 3
    Last Post: 08-24-2010, 11:50 AM
  4. Working with PDF's
    By Mitch87 in forum Access
    Replies: 1
    Last Post: 02-19-2010, 11:24 AM
  5. Why isn't this working?
    By adiecidue in forum Queries
    Replies: 4
    Last Post: 04-27-2009, 10:29 AM

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