Results 1 to 7 of 7
  1. #1
    mjhd is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    5

    IIf Statement Validation Rules or Expression in Form

    Hey there,



    After some lengthy investigating, I am unable to find a solution to my problem. I have a form where a user enters data in a field called [Value]. One of the fields is called [Product], it simply has a value of either Y or N. Based on this field, I would like the field [Value] to be either 0 or null and a message pops up if it isn't either one (if [Product] = N). If it is = Y, then it can be either 0 or null or any number. Thanks for nay help.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Personally I'd use the before update event of the form:

    http://www.baldyweb.com/BeforeUpdate.htm

    with the logical test adjusted to your needs.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    mjhd is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    5
    The statement I tried btw is:

    =IIf([Product]="N",0 or is null, IIf[Product]="Y",0 or is null or [Value]...

    The issue I'm having as well is that besides 0 or null when = Y, I would need the user's input to stand as well if they enter a number. I tried it in before update, did not give a suntax error but didn't do anything either.

  4. #4
    qa12dx is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    india
    Posts
    112
    =IIf([Product]="N",-1, IIf([Product]="Y",1,0))
    what it's saying here is;
    if prod =n then val=-1, else if prod=y then val=1, else val 0

    suggestion, dont use NULL values. save urself lots of tears...

  5. #5
    mjhd is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    5
    Quote Originally Posted by qa12dx View Post
    =IIf([Product]="N",-1, IIf([Product]="Y",1,0))
    what it's saying here is;
    if prod =n then val=-1, else if prod=y then val=1, else val 0

    suggestion, dont use NULL values. save urself lots of tears...
    But I still need the user to be able to enter values in the [Value] field. They might enter 350, 1500, etc.

  6. #6
    qa12dx is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    india
    Posts
    112
    what u r saying is after the user puts in a value, if that value exists then the prod field will be y else n? for that you will have to run a "after update" event from that control box. after update use a dcount func. if the value is >0 then set the pord value

  7. #7
    mjhd is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    5
    Quote Originally Posted by qa12dx View Post
    what u r saying is after the user puts in a value, if that value exists then the prod field will be y else n? for that you will have to run a "after update" event from that control box. after update use a dcount func. if the value is >0 then set the pord value
    I'm saying if the [Product] field is = Y, then allow the user to put in a #,0, or even leave null in the [Value]. If the [Product]=N, then the user can only put in a 0 or leave as null.

    Alternatively, I could just have [Value] default to 0 if [Product]=N, and not allow any edits. But the user must still be able to edit the [Value] field if [Product]=Y.

    Any ideas?

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

Similar Threads

  1. Validation Rules Help
    By Troop in forum Access
    Replies: 11
    Last Post: 03-05-2013, 01:26 PM
  2. Field rules/validation rules
    By sk88 in forum Access
    Replies: 14
    Last Post: 02-26-2012, 01:03 PM
  3. troubles with validation rules
    By focosi in forum Access
    Replies: 4
    Last Post: 08-02-2011, 10:46 AM
  4. Multiple Validation Rules in a form
    By GothardTech in forum Forms
    Replies: 1
    Last Post: 04-15-2011, 01:21 PM
  5. Validation Rules
    By esglover in forum Database Design
    Replies: 1
    Last Post: 07-23-2010, 08:02 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