Results 1 to 7 of 7
  1. #1
    thexxvi is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    63

    Creating an IF statement in a Database

    Good afternoon,



    I have a table and need to create an if statement in a field that is dependent on another field. So if Field A shows "yes", then Field B would result in a certain value. If field A shows "no", then Field B would result in a blank.

    How can I complete this?

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    IMHO that would make Field B a calculated field and as such it would probably be better not to store this value in a table. Better to calculate the value whenever and where ever it is required.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Here is a link on how to use the IIF function in an Access query to do what you want: http://www.techonthenet.com/access/f...vanced/iif.php

  4. #4
    thexxvi is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    63
    Thank you for the responses. I just made the field a calculated field and it is updating that information in the database, but it's not showing the update on the form. For example, I update Field 1 with "Yes" and Field 2 is supposed to show a certain value. That value appears on the database, but is not showing up on the form. Any ideas why the value wouldn't show up on the form?

  5. #5
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You still haven't answered my question.
    Exactly WHERE have you placed this calculated field?
    On the Form itself? In the underlying Query? In the Table?
    A database is made up of all these objects, so saying the "database" does not really narrow it down.

  6. #6
    thexxvi is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    63
    I didn't see a question in your initial post JoeM, but to answer your question, it's in the table.

    I figured it out though. I set the field up as a calculated field in the table and placed a refresh macro on the form and it works perfectly.

    Thanks everyone.

  7. #7
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Glad you got it figured out.
    I would recommend against putting calculated fields in tables. While Access does now allow that functionality, almost all database programs (like SQL, Oracle, etc) do not. So if you ever needed to convert your database to a "real" database back-end, you would have some issues.

    It is generally recommended to do all those calculations in a query, and then use the query as the Data Source of your Form (instead of the Table).

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

Similar Threads

  1. Replies: 11
    Last Post: 04-29-2015, 01:38 PM
  2. Creating an IF statement within a Form
    By csd003 in forum Forms
    Replies: 3
    Last Post: 07-29-2014, 01:27 PM
  3. Creating an FAQ database
    By rescobar in forum Database Design
    Replies: 14
    Last Post: 08-01-2013, 02:53 PM
  4. Creating If Statement in form
    By MaxLev in forum Forms
    Replies: 1
    Last Post: 12-11-2012, 02:06 AM
  5. Creating a database
    By WayneSteenkamp in forum Access
    Replies: 7
    Last Post: 02-28-2012, 07:13 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