Results 1 to 8 of 8
  1. #1
    sf827 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    16

    How to write an expression referring to two values from the same field

    I'm a long-time excel user in the process of converting to access.

    What's the simplest way write an expression which refers to specific values from the same field?

    If I was using excel I'd use cell references. E.g.

    =IF(B3>B2,"Default","Valid")

    Thanks

  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,640
    Depends on where, but in general the equivalent would be:

    =IIf([Field1]>[Field2],"Default","Valid")

    Note the IIf() function rather than IF, which is only valid in VBA code.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    sf827 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    16
    Thanks for the (super) quick reply pbaldy.

    Forgive me if this is a stupid question but wouldn't your expression compare two different fields?

    I probably wasn't clear - I'm trying to compare two values from the same field.

    For example, if we imagine a table in datasheet view, I'd like to write an IIf expression which returns "Default" if the value in row 3 of [Field 1] is greater than the value in row 2 of [Field 1].

    I suppose another way of asking the question is - is it possible to identify values by describing their relationship to the "row" containing the expression?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Sorry, you did say that but I was focused on the B in the formula, thinking that meant same record. The order of records in a table has no meaning, so you wouldn't refer to it as a relationship to the current row. Typically you'd do something like this:

    http://www.allenbrowne.com/subquery-...#AnotherRecord

    Does that seem like it would work?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    sf827 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    16
    Yes that should give me a starting point.

    I see your point about the order of values being meaningless.

    Thankyou!

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    No problem, and welcome to the site! Sorry about heading down the wrong track.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    JustAccess is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    4
    I am trying to do something similar but I am so new to ACCESS that the link you provided earlier is still greek to me! I have combined 2 fields to create a unique (should be unique) field identifier for each row. I now need to determine if I have any duplicates listed in the newly created field (CLIN Dup).

    example:

    Rel # CLIN CLIN Dup
    10DL 0001 10DL0001
    10DL 0002 10DL0002
    10DL 0003 10DL0003
    10DL 0002 10DL0002

    Any help would be appreciated as I am stumped

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Try this query:

    SELECT [CLIN Dup]
    FROM TableName
    GROUP BY [CLIN Dup]
    HAVING Count(*) > 1
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. VBA: Read table & write values to another table
    By compooper in forum Programming
    Replies: 6
    Last Post: 07-29-2011, 11:19 AM
  2. Replies: 1
    Last Post: 05-11-2011, 02:51 AM
  3. Replies: 1
    Last Post: 06-24-2010, 08:08 AM
  4. How to write field values next to each other?
    By Petefured in forum Programming
    Replies: 2
    Last Post: 09-23-2009, 02:39 PM
  5. Write excel expression in access
    By ktmchugh in forum Queries
    Replies: 0
    Last Post: 07-01-2009, 02:47 PM

Tags for this Thread

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