473,385 Members | 1,958 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,385 software developers and data experts.

Modify duplicate records using VBA code

Hello,

Can someone please paste VBA code and how I would go about doing
this?:

I have a customer table with over 6000 duplicates in the field called
"Customer". While the customer names may be duplicates the data in
other fields is different. I would like to import all of the customers
including the duplicates; however, the program I am importing into
doesn't allow duplicate customer names.

Therefore, my goal is to loop through the table using VBA, if
possible, and for each duplicate in the Customer field, add a number
or character.

For example:

John Doe1
John Doe2
John Doe3

Jane Smith1
Jane Smith2

If you can provide instructions on how to create and run the VBA code,
that would be appreciated.

Thanks,
Brett
Jun 30 '08 #1
5 1833
MLH
On Mon, 30 Jun 2008 08:37:11 -0700 (PDT), "Brett Barry: Go Get Geek!"
<br*********@gmail.comwrote:
>Hello,

Can someone please paste VBA code and how I would go about doing
this?:

I have a customer table with over 6000 duplicates in the field called
"Customer". While the customer names may be duplicates the data in
other fields is different. I would like to import all of the customers
including the duplicates; however, the program I am importing into
doesn't allow duplicate customer names.

Therefore, my goal is to loop through the table using VBA, if
possible, and for each duplicate in the Customer field, add a number
or character.

For example:

John Doe1
John Doe2
John Doe3

Jane Smith1
Jane Smith2

If you can provide instructions on how to create and run the VBA code,
that would be appreciated.

Thanks,
Brett
I'm not sure you're gonna get much help
from this forum on this request. Your key
statement is...

"...the program I am importing into doesn't
allow duplicate customer names..."

I think that program you're using is trying
to tell you something. There are lot's of
ways to append additional string data
onto strings. Getting the sequential integers
appended onto the ends of your customer
names isn't gonna be difficult. Recovering
from the mess made by doing so will be.
Jun 30 '08 #2
Getting the sequential integers
appended onto the ends of your customer
names isn't gonna be difficult.
This is what I want to do.
Jun 30 '08 #3
MLH
>
>This is what I want to do.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

OK - Is it a one-time thing? That is,
once you do it, you won't have to
do it again. And, does it matter what
the additional unique identifiers are
that you tack on to the end of the
customer name strings? And last,
do all the records containing cust
name strings have unique index
field values?

Assuming the answers are Yes,
No and Yes respectively. Extract
duped records, outputting only
the [UniqueID] and [CustName]
fields. Using a MakeTable qry
to create the target table would
make this easier. Call it NewTable.
Open NewTable in Design view.
Change the field type of [UniqueID]
to LongInteger if it's AutoNumber.
Add a new field named [ID] to the
table - AutoNumber type. Save the
table. Create a query based on
NewTable, outputting all fields.
Put a calculated field in the query
named [NewCustName] like this...
NewCustName: [CustName] & Trim$(CStr([CustName]))

Run the query. There are your
new customer names. Paste 'em
into a new test copy of your table,
overwriting the previous redundant
values with the new, unique values.

Jun 30 '08 #4
I'm not sure if this is related, but I would prefer VBA code that
loops through and for each duplicate of the same name, add a number in
sequence, similar to this code that deletes the duplicates:
1.
Function DeleteDuplicates_Click()
2.
On Error Resume Next
3.

4.
Dim db As Database, rst As Recordset
5.
Dim strDupName As String, strSaveName As String
6.
Dim strSQL As String
7.
strSQL = "SELECT [JOBNUM], [trnd] FROM Tableqryduplicates"
8.

9.
Set db = CurrentDb()
10.
Set rst = db.openrecordset(strSQL, dbOpenSnapshot)
11.

12.

13.
If rst.BOF And rst.EOF Then
14.
MsgBox "No records to process"
15.
Else
16.
rst.MoveFirst
17.
Do Until rst.EOF
18.
strDupName = rst.Fields("JOBNUM") & rst.Fields("trnd")
19.

20.
If strDupName = strSaveName Then
21.
rst.Delete
22.
Else
23.
strSaveName = rst.Fields("JOBNUM") & rst.Fields("trnd")
24.
End If
25.
rst.MoveNext
26.
Loop
27.

28.
rst.Close
29.
Set rst = Nothing
30.
Set db = Nothing
31.
End If
32.

33.

34.
End Function
Jun 30 '08 #5
MLH
Can't help you there. Maybe someone
else will jump in.

Jul 1 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Sam G | last post by:
Hi all, I have been left to modify an old unique index, which no longer works, as the two fields, which were used, are no longer unique. I’ve found two others that are unique. But as I’m new to...
0
by: Schlauberger | last post by:
I am currently developing an application in VB dot Net where I am using MS Access parameter query as a data source. I have simplified my code but I am still generating a duplicate set of records?...
2
by: ms | last post by:
Access 2000: I am trying to delete duplicate records imported to a staging table leaving one of the duplicates to be imported into the live table. A unique record is based on a composite key of 3...
2
by: stranger | last post by:
My database is set up so people can input parts orders. Sometimes they order the same parts on a monthly basis. I want to be able to duplicate past parts orders and have it pasted in with a new...
4
by: afr0ninja | last post by:
Hello! I'm still rather new to using code in access. I've come across a problem that I'm having difficulty troubleshooting. Any assistance would be greatly appreciated! I've set up a form...
4
by: mcca0081 | last post by:
hi - i'm trying to delete one of the duplicate records based on the most current date. here's the code for my access 2000 db. any help would be appreciated!!! - thank you kindly Sub...
2
by: nethravathy | last post by:
Hi, The following table namely elcbtripselect contains 5147 records.I want to know wether this table contains duplicate records or not. I tried with following query 1)SELECT...
2
by: nomvula | last post by:
hi guys i need some help to duplicate records on my form datasheet: here's the example of my form results: ClientLookup DateCaptured ForecastDate Description ForecastQuantity Forecast Actual UJ...
1
by: xraive | last post by:
I have a problem with this. Currently I am trying Allen's code and i am not successful. Current Design Table1 (Main Form) TravelID (PK) ApprovedBY EntreredBy BudgetCode ExpenseCode
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.