473,499 Members | 1,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parsing Duplicates Using VBA

124 New Member
I am trying to take one semi-colon separated field (Custodian) which contains multiple names and may or may not contain duplicate names. I split the field based on semicolon and created new ones for each name in Custodian (Cust0, Cust1, Cust2, etc.) Now I need to parse out the duplicates and combine the non-dupe fields to make the NewCustodian field, but am having a hard time with it. I made code that will mark each duplicate entry in the table tblDupes, which contains the fields DOCID, 0,1,2,3,4,5,6,7,8,9,10. I use the following code to mark which fields are dupes. This works okay except that if Cust0 and Cust4 are duplicates, it will enter -1 into Fields 0 and 4 in the tblDupes table, when I actually want to keep the values from one of the fields to concatenate into my new dupe free NewCustodian field.
Expand|Select|Wrap|Line Numbers
  1. Function DeDupe()
  2. Dim DB As DAO.Database
  3. Dim RS As DAO.Recordset
  4. Dim strSQL As String
  5. Dim arMulti() As String
  6. Dim strOrigCust As String
  7. Dim intUbound As Integer
  8. Dim i As Integer
  9.  
  10. Dim strCust0 As String
  11. Dim strCust1 As String
  12. Dim strCust2 As String
  13. Dim strCust3 As String
  14. Dim strCust4 As String
  15. Dim strCust5 As String
  16. Dim strCust6 As String
  17. Dim strCust7 As String
  18. Dim strCust8 As String
  19. Dim strCust9 As String
  20. Dim strCust10 As String
  21. Dim strCust11 As String
  22. Dim intFirstFind As Integer
  23. Dim intDupe1 As Integer
  24. Dim intDupe2 As Integer
  25. Dim intDupe3 As Integer
  26. Dim strControlID As String
  27.  
  28.  
  29.  
  30.  
  31. Set DB = CurrentDb
  32. strSQL = "Select * From qryDupe1_MultipleCust"
  33. Set RS = DB.OpenRecordset(strSQL)
  34.  
  35. Dim strDupesSQL As String
  36. Dim DupeRS As DAO.Recordset
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. RS.MoveFirst
  45. Do Until RS.EOF
  46.     strOrigCust = RS!Custodian
  47.     strControlID = RS![DOCID]
  48.     arMulti() = Split(strOrigCust, ";")
  49.     intUbound = UBound(arMulti())
  50.     strDupesSQL = "Select * from tblDupes Where ControlID = '" & strControlID & "'"
  51.     Set DupeRS = DB.OpenRecordset(strDupesSQL)
  52.  
  53.     For i = 0 To intUbound
  54.  
  55.  
  56.         intFirstFind = InStr(1, strOrigCust, Nz(Trim(RS("Cust" & CStr(i)))))
  57.         If InStr(intFirstFind + 1, strOrigCust, Trim(RS("Cust" & CStr(i)))) Then
  58.             'Set DupeRS = "Select * from tblDupes"
  59.             DupeRS.Edit
  60.             DupeRS(CStr(i)) = -1
  61.             DupeRS.Update
  62.            'intDupe2 = InStr(intFirstFind + 1, strOrigCust, RS("Cust" & CStr(i)))
  63.  
  64. '            RS.Edit
  65. '            RS("Cust" & CStr(i)) = Null
  66. '            RS.Update
  67. '
  68.         End If
  69.     Next
  70. RS.MoveNext
  71. Loop
  72.  
  73. MsgBox "Fields parsed", vbCritical, "FILE'S DONE"
  74.  
  75.  
  76. End Function
  77.  
Any advice is welcome and I hope this is not a double post. I posted this before and nothing showed up on the blog.
Nov 16 '15 #1
7 1232
jimatqsi
1,271 Recognized Expert Top Contributor
Here's one way I might that sort of thing.
Expand|Select|Wrap|Line Numbers
  1. Do Until RS.EOF
  2.     strOrigCust = RS!Custodian
  3.     strControlID = RS![DOCID]
  4.     arMulti() = Split(strOrigCust, ";")
  5.     intUbound = UBound(arMulti())
  6.     strDupesSQL = "Select * from tblDupes Where ControlID = '" & strControlID & "'"
  7.     Set DupeRS = DB.OpenRecordset(strDupesSQL)
  8.  
  9.     strOrigCust=""     ' init our string so we can rebuild it
  10.     For i = 0 To intUbound
  11.      strOrigCust=replace(strOrigCust & ";","") ' remove this one if it is already there
  12.     strOrigCust = strOrigCust  & arMulti(i) & ";"    ' now add this one
  13.     next
  14.     rs.edit
  15.     rs!Custodian=strOrigCust  ' replace with our updated string
  16.     rs.update
  17.  
  18. ''        intFirstFind = InStr(1, strOrigCust, Nz(Trim(RS("Cust" & CStr(i)))))
  19.  ''       If InStr(intFirstFind + 1, strOrigCust, Trim(RS("Cust" & CStr(i)))) Then
  20.  ''           'Set DupeRS = "Select * from tblDupes"
  21.  ''           DupeRS.Edit
  22.  ''           DupeRS(CStr(i)) = -1
  23.  ''           DupeRS.Update
  24.  ''          'intDupe2 = InStr(intFirstFind + 1, strOrigCust, RS("Cust" & CStr(i)))
  25.  
  26. '            RS.Edit
  27. '            RS("Cust" & CStr(i)) = Null
  28. '            RS.Update
  29. '
  30. ''        End If
  31. ''    Next
  32. RS.MoveNext
  33. Loop
  34.  
Nov 16 '15 #2
jimatqsi
1,271 Recognized Expert Top Contributor
Of course you could substitute this for lines 11 and 12
Expand|Select|Wrap|Line Numbers
  1. if instr(strOrigCust,arMulti(i) & ";")=0 then
  2.     strOrigCust=strOrigCust & arMulti(i) & ";"
  3. end if
Nov 16 '15 #3
zmbd
5,501 Recognized Expert Moderator Expert
My vote would be to use the instr() as J does in post#3.
Using your upperbound on the array and a for..next loop to step thru the array and avoid the potential bloat from temp-tables and the overhead of a record-set.

Out of curiosity why store the names in a single field, normally, I would have thought that a table to store the names as individual records and then concatenate them as needed via query just to avoid such a mess would be preferable.
Nov 17 '15 #4
NeoPa
32,557 Recognized Expert Moderator MVP
I'd look at digging up a sort routine from the web then working with the sorted results.
Nov 17 '15 #5
BikeToWork
124 New Member
Thanks for the advice. It worked a treat.
Nov 17 '15 #6
BikeToWork
124 New Member
ZMBD, the semicolon separated fields are not from Access but rather are Relativity data, a Lit Support application which uses SQL Server for a back end and it is known as a "Multi Choice" type field and stores data in these fields in semicolon delimited format.
Nov 17 '15 #7
zmbd
5,501 Recognized Expert Moderator Expert
eeegads the multi-value field somewhere else other than in an Access database!

shudder and tremble in fear the world is coming to an end (@_@)
Nov 18 '15 #8

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

Similar topics

6
1743
by: * | last post by:
I need to devise a way of reading the following XML data and taking the Job_ID and putting into a database using the access_code and the adt_company_id. any idea of how I might be able to do...
0
1479
by: burn_hall | last post by:
Hi, I have a problem and can't figure it out and need your help, please look at the following code and the output also a xml file snippet is down there too. Looking at the output I don't know why...
1
4989
by: bird | last post by:
?sitem <?xml version="1.0"?> <RootNode> ' one root node <Transaction> ' doc element node <AccountNumber>1001000</AccountNumber> '...
0
1069
by: rufus | last post by:
Hi, I need to parse some html that contains the comments: <!-- Start Display ---> and <!-- End Display ---> . I need to capture all the HTML between these comments. I started with: r = New...
0
1050
by: Kota | last post by:
Hi, I am using webservice to get data from database and using in VBA of visio. in web service I am using dataset.GetXml() method to return XML string. using this string I want to parse...
0
1928
by: Seth | last post by:
First off, my apologies if this is in the wrong newsgroup, but I hope I'm close enough. I'm trying to do some parsing of a CSV file using OleDbConnection, but for some reason, when I populate my...
2
1852
by: REG | last post by:
Hi All, Could someone point me in the right direction ... have been searching for days for a code snippit or a tuitorial that will show how to: 1. Load XML data into an Html Page in a way that is...
0
961
by: hzgt9b | last post by:
Using VB.NET under .NET 1.1 in VS2003, BACKGROUND I have a windows application that dereferences the MsHTM.dll. The app is successfully able to parse existing HTM documents allowing me to...
1
1195
by: Jon86 | last post by:
Hi All, Please help me in developing a windows application for parsing a page form webbrowser control into a tree view control in the windows form, using C# .. Cheers Jon
5
5780
by: sbettadpur | last post by:
We are developing a recruitment tool.For that I want to do ''Resume Parsing' in PHP.I was able to parse Email-id and Phone No. .But i do not know how to parse the candidate's full name and address...
0
7014
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
7229
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...
1
6905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4921
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3108
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.