Results 1 to 5 of 5
  1. #1
    SamuelOu is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2015
    Posts
    16

    Building relationship between similar fields

    Hi,



    I have two tables share a column with similar codes:

    Table 1: the codes are as "AB-CDE", "SDF-FDS", "LKJ-SLD"

    Table 2: the codes are as "AB-CDE-001", "AB-CDE-002", "SDFFDS-01", "LKJSLD-007"

    Is it possible to build relationship among these two fields without VBA programming?

    Thank you so much!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Review this recent thread about string manipulation https://www.accessforums.net/access/...ent-50262.html

    Removing the hyphens would be easy. The number suffix complicates.
    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
    SamuelOu is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2015
    Posts
    16
    Thanks. However, every code has at least two hyphens, such as "AB-CD-E" to "AB-CD-E-001" or "AB-CD-E-02". My goal is removing the last hyphen and anything behind it.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Okay, try:

    x represents the field name

    For table1

    Replace(x,"-","")

    For table2

    Replace(Left(x, InStrRev(x, "-")), "-", "")

    A query could be like:

    SELECT Table1.*, Table2.* FROM Table1 INNER JOIN Table2 ON Replace(Table1.[fieldname],"-","") = Replace(Left(Table2.[fieldname], InStrRev(Table2.[fieldname], "-")), "-", "");
    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.

  5. #5
    SamuelOu is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2015
    Posts
    16
    It works, THANKS A LOT!

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

Similar Threads

  1. Replies: 6
    Last Post: 06-19-2014, 12:29 PM
  2. Relating similar fields???
    By smoothlarryhughes in forum Access
    Replies: 10
    Last Post: 02-26-2013, 12:50 PM
  3. Replies: 4
    Last Post: 07-13-2012, 01:41 PM
  4. building a one to many relationship
    By medused in forum Database Design
    Replies: 3
    Last Post: 06-27-2012, 03:44 PM
  5. Building Relationship: one to many
    By Keeper in forum Access
    Replies: 1
    Last Post: 04-25-2012, 05:31 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