Results 1 to 3 of 3
  1. #1
    tcrwt is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    2

    Autofill Field Based On Another Field

    I have a problem which I'm sure is easy to solve. I've never used access before and I'm working my way through. I have searched around but I can't find the answer... so, here's my problem.

    I have two fields that are relevant, currently within the same table.

    The first field is called RAC, and it is a combobox with two options (well, three?): 12 Months, 24 Months, and blank (this is the length, if any, of the policy the customer takes out). The next field is called RAC Price, and it simply needs to return 80 if RAC is 12 Months, 150 if RAC is 24 Months, and 0 if RAC is blank. Preferably these numbers will be preceded by £, but that's not vital.

    I, being very new, tried to set the RAC Price field to a calculate field with the formula:



    IIf( [RAC]="12 Months","80","") AND IIf( [RAC]="24 Months","150","") AND IIf( [RAC]="","0","")

    But unsurprisingly this didn't work. It returns 0 for an empty RAC field, and -1 for any value in the field, no matter what it is. I guess it's to do with the fact that two of the conditions will return false no matter what's in the RAC field, so they're giving conflicting info.

    Anyway, could I please have some help? All I need is for RAC Price to return something based on RAC. It doesn't matter if this happens in the field input in the form or in the column in the table.

    Thanks in advance!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,619
    Don't use AND operator. RAC can be only one value.

    You need a nested IIf:

    IIf([RAC]="12 Months",80,IIf([RAC]="24 Months",150,0))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    tcrwt is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    2
    It worked like a charm. Thank you so much! I can't believe it was so close to what I put!

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

Similar Threads

  1. Replies: 2
    Last Post: 07-14-2011, 09:23 AM
  2. PLEASE help: Autofill based on one field
    By Suzanne in forum Forms
    Replies: 5
    Last Post: 07-07-2011, 11:09 AM
  3. Autofill of a field based on another
    By MyWebdots in forum Forms
    Replies: 7
    Last Post: 07-12-2010, 05:00 AM
  4. Autofill form fields based on another field
    By ljs1277 in forum Access
    Replies: 3
    Last Post: 02-16-2010, 02:51 PM
  5. Autofill field based on autonumber field
    By frevilla in forum Forms
    Replies: 1
    Last Post: 09-11-2009, 02:50 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