473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to pull list of record by pulling 1st record of duplicate IDs

Hi All,

I am looking for guidance in MS access.

I have a data table with 3 column CustomerID, ContactID and Contact number. The CustomerID column has duplicate IDs but ContactID has unique IDs. I want to export data this table using CustomerID but only 1st instance of each duplicate and any unique CustomerID so let say I was to pull 10011 1st instance in one table.
Likewise, I would need to create second export with all 2nd instance duplicate in different table and so on.

Can I do that?

below is example data
CustomerID ContactID Contact number
10011 123XXY 04XXXXXX
10012 113XXY 02XXXXXX
10011 223XXY 03XXXXXX
10012 133XXY 07XXXXXX
10011 423XXY 08XXXXXX
Oct 10 '19 #1
4 740
NeoPa
32,556 Expert Mod 16PB
Hi Nischay.

Welcome to Bytes.com.

At this point I can only advise that you edit your question so that it makes sense to people who don't already know what you're talking about. Many won't say anything but just ignore your question because it's so unclear what you mean.

Generally speaking, if you update it of course, you'll see a number jumping in trying to help. Left as it is then not so much.

Good luck.
Oct 11 '19 #2
Thanks Neo, I have updated the query. Hope this make sense
Oct 11 '19 #3
NeoPa
32,556 Expert Mod 16PB
Not a lot if I'm honest. My best guess would be that you mean you have it working and no longer need help, but that can only be a guess at this point.
Oct 11 '19 #4
cactusdata
214 Expert 128KB
You can write some fancy SQL using TOP n in several levels, but it is much simpler to add a field, Exported, to the table, then loop the table while marking the records as exported:

Expand|Select|Wrap|Line Numbers
  1. Public Function ExportContacts()
  2.  
  3.     Dim rs  As DAO.Recordset
  4.     Dim Id  As String
  5.  
  6.     Set rs = CurrentDb.OpenRecordset("Select * From Contacts Where Exported = False Order By 1, 2")
  7.  
  8.     While Not rs.EOF
  9.         If Id <> rs!CustomerID.Value Then
  10.             Id = rs!CustomerID.Value
  11.             ' Run export - like appending data to another table.
  12.             Debug.Print rs!CustomerID.Value, rs!ContactID.Value, rs![Contact number].Value
  13.             rs.Edit
  14.                 rs!Exported.Value = True
  15.             rs.Update
  16.         End If
  17.         rs.MoveNext
  18.     Wend
  19.     rs.Close
  20.  
  21. End Function
Results from 1st, 2nd, 3rd run of the above function:

Expand|Select|Wrap|Line Numbers
  1. 10011         123XXY        04XXXXXX
  2. 10012         113XXY        02XXXXXX
  3.  
  4. 10011         223XXY        03XXXXXX
  5. 10012         133XXY        07XXXXXX
  6.  
  7. 10011         423XXY        08XXXXXX
Oct 11 '19 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: The Biscuit Eater | last post by:
Just started "playing" with php and have a question. I currently have a csv list such as this: 11-08-03 | Tournament | Chapman rules 12-18-03 | Beat The Pro | pick your partner etc. Is there...
5
by: Andrew | last post by:
Hi All, Have come across something weird and am after some help. Say i run this query where rec_id is a column of table arlhrl, select * from arlhrl where rec_id >= 14260 This returns to...
1
by: Tony | last post by:
Thanks for writing back and don't laugh at what I am about to post I am new to this type of stuff....this is what I have tried and it isn't working(please note in the try section I was just trying...
3
by: Mark V. | last post by:
Here's what I have and I'm stumped. I have a table that has several thousand names and addresses. I only want to send to one address in a household. So what I would like to do is create a new...
3
by: BillB | last post by:
When I activate frmList.List0, it positions at the end of the table: - frmList Private Sub Form_Activate() Me.List0.SetFocus Me.List0.ListIndex = Me.List0.ListCount - 1 - When I DblClick a...
15
by: Susan Bricker | last post by:
Greetings. I have a Mainform with a subform. The Mainform has single record format and subform has continuous form format. When the Mainform opens, I force allowadditions and allowedits to FALSE...
1
by: Himmel | last post by:
I may be brain-fried, but I could use some help again. One of my glorious forms in my multi-form report thingiemajigger is a tabular form. For example, it shows customer items purchased and the...
1
by: bemadragon | last post by:
Hello, I have been struggling with this for a while. I am working on a rather simple database for calculation purposes in Access 2003. I have a table called Order that has a primary key field...
3
Seth Schrock
by: Seth Schrock | last post by:
I've got a way for the user to delete the record. The user just didn't know it. I might end up putting a Delete button next to the Undo button so that they can find it easier. An idea just...
3
by: Lagarizta | last post by:
*single MS ACCESS FILE *ACCESS FILE contains one form that serves as a query form. Form has a GENERATE button which will display on the right the row number record and will auto populate the form...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.