Results 1 to 4 of 4
  1. #1
    cbende2's Avatar
    cbende2 is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jun 2014
    Location
    Louisiana
    Posts
    370

    Question Comparing two fields

    Hey guys,

    SKIP TO TABLE FOR SIMPLE EXPLANATION:

    I'm trying to import a list into my database from excel.

    It will be a new table that I would like linked to my main Table1.

    Table one has PK1, however, we also store PK2 from another database. PK2 is only used for the other database, it is in my database for simplicity when looking up info. It does not hold a primary key role in my database, it is simply a text field. In the other database it is the primary key role.

    Now the problem:

    I have an excel spreadsheet with PK2 located in it.

    After exporting Table1 from my database, I need to look for PK2 in my database, and add PK1 to the excel spreadsheet where PK2(my database) = PK2(excel spreadsheet)

    Table for example:


    MY spreadsheet


    (A)
    PK2(excel)
    (B)
    PK1(excel)
    (C)
    PK2(mydatabase)
    (D)
    PK1(mydatabase)
    ALLIANCE ALLIANCE 1
    ALLIANCE BARTH 2
    BARTH CASS 3
    COOR COOR 4
    COOR DEEP 5

    I'm looking for a formula that compares column (C) with column (A), and whenever there is a match, populate column (B) with the value in column (D).

    So the finished result would look like:
    (A)
    PK2(excel)
    (B)
    PK1(excel)
    (C)
    PK2(mydatabase)
    (D)
    PK1(mydatabase)
    ALLIANCE 1 ALLIANCE 1
    ALLIANCE 1 BARTH 2
    BARTH 2 CASS 3
    COOR 4 COOR 4
    COOR 4 DEEP 5

    Its not too hard to understand. I'm just not sure how to go about doing this process. I had no luck with Vlookup.

    I know this is an excel question, however I'm a frequent at this website so I figured I'd give it a shot here!

    Thanks!

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I see an Inline If (iif) statement with an Alias as an argument in your future. I would use this Inline If as a second alias within a query object.

  3. #3
    cbende2's Avatar
    cbende2 is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jun 2014
    Location
    Louisiana
    Posts
    370
    That was a little over my head, but I'll do some research.

    Could you explain a little further?

    So something like:

    Iif(ColumnA = ColumnC) Update ColumnB to ColumnD Where ColumnA=ColumnC

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Kinda, yes. There is not a ternary operator in VBA so the VBA answer to a ternary operator is an IIF() function.

    https://msdn.microsoft.com/en-us/lib.../gg264412.aspx
    Check out the above link and you will see an example that I broke. Here, I illustrate where you might be able to place some alias'
    Code:
    SomeAlias: IIf(TestMe > 1000, AliasMyCalc, SomeOtherColumn)

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

Similar Threads

  1. Criteria comparing two fields
    By Metrazal in forum Queries
    Replies: 3
    Last Post: 08-15-2014, 03:03 PM
  2. iif statement comparing two fields
    By unslog in forum Access
    Replies: 6
    Last Post: 09-28-2012, 02:13 PM
  3. Subquery comparing two fields
    By jdcollins in forum Queries
    Replies: 8
    Last Post: 01-17-2011, 02:02 PM
  4. Comparing fields in Access
    By flames8889 in forum Queries
    Replies: 2
    Last Post: 04-20-2010, 11:55 AM
  5. Comparing between fields
    By Dashin in forum Queries
    Replies: 0
    Last Post: 02-13-2009, 08:38 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