Results 1 to 3 of 3
  1. #1
    bg_bb is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1

    Cool Macro/code to add records to fields

    I have a table that contains duplicate ID’s for those who have more than one telephone number. How can I write a macro or a module that would take each phone number and add it to a column (Phone Number 1, Phone Number 2) so that I will only have 1 record for each ID.

    How it is currently
    ID Phone Number
    1 111-111-1111
    2 222-222-2222
    2 222-000-0000
    3 333-333-3333
    4 444-444-4444
    4 444-000-0000

    How i want it to be


    ID Phone Number 1 Phone Number 2
    1 111-111-1111
    2 222-222-2222 222-000-0000
    3 333-333-3333
    4 444-444-4444 444-444-0000

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    I think you could do this with a crosstab query
    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
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,944
    A CROSSTAB query would require a group record identifier. This can be calculated in a query with DCount() function and then use that query as source for CROSSTAB. Can be nested subquery.

    TRANSFORM First(PhoneNumber) AS FirstOfPhoneNumber
    SELECT ID
    FROM (SELECT ID, PhoneNumber, DCount("*","TableName","ID=" & [ID] & " AND PhoneNumber<" & [PhoneNumber])+1 AS GrpSeq FROM TableName) AS Q1
    GROUP BY ID
    PIVOT GrpSeq;
    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.

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

Similar Threads

  1. Help with NPV Macro Code in VBA
    By BigNasty in forum Macros
    Replies: 6
    Last Post: 11-21-2016, 10:39 PM
  2. How to run Data macro using VBA Code.
    By pritesharyan in forum Access
    Replies: 2
    Last Post: 06-18-2015, 09:17 AM
  3. Help with access code (macro?) please
    By visidro in forum Programming
    Replies: 10
    Last Post: 03-15-2013, 05:56 PM
  4. VBA code or Access Macro
    By CSGabriel in forum Access
    Replies: 1
    Last Post: 07-27-2012, 09:08 AM
  5. VBA code/Macro help please.
    By Davidyam in forum Access
    Replies: 1
    Last Post: 02-26-2012, 09:59 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