Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to create a vba script that would parse out data from tables in Microsoft Access?

Posted on 2014-12-08
3
Medium Priority
?
217 Views
Last Modified: 2016-02-10
I have a table where I have a number field that contains a CONTROL ID.  In this table, we have a custodian and location fields. So the custodian field contains names of people. It can be one or multiple. Location files contains the file paths for all of the data.  So, I need to combine our custodian field with the location field. So for the example, the custodian field can look like this:

Custodian                                                                                              Location
Smith,John;Doe,Jane;Powell,Dan                                            \\Servername\PathforJohnSmith|\\Servername\PathforJaneDoe|\\Servername\PathforDanPowell.

Keep in mind that the Location paths are not a set number of characters, they have vary. Custodian can contain one value or multiple values so I need my vba script to loop until there are no more names to pair up with the location.  So the end result was Smith,John::\\Servername\PathforJohnSmith;Doe,Jane::\\Servername\PathforJaneDoe;Powell,Dan::\\Servername\PathforDanPowell in one field call All Custodians Locations.


To be able to accomplish this I created a series of queries. I used this expression first: Left([Location],InStr([Location],";")-1) to extract the first location into a separate field, then used the Right([Duplicate Locations],Len([Duplicate Locations])-InStr([Duplicate Locations],"|")) that gave me the remaining locations.  This works on the custodian field with the names as well since both fields had delimiters.

I would have to repeat this process over and over again until all of the locations are extracted. This is the same with the custodian field as well. Then I would make up the fields with the location with concatenated.

I would like to automate this more within an Access database so it won't take me as long as it did for future work. Any suggestions would be happily received.
0
Comment
Question by:lauriecking
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 39

Accepted Solution

by:
PatHartman earned 1000 total points
ID: 40487800
Where does this data come from?  Are you stuck with keeping it this way or can you normalize it?  You need at least one more table so you can keep a single row per custodian.  That assumes that there is only one location per custodian.  If a custodian may have multiple locations, you'll need a second new table.

Look at the Split() function.  You can use the semi-colon to split the custodian names into an array.  Then you can loop through the array and write a record for each custodian after you separate the first name and last names into SEPARATE fields.

Assuming the data in the location field is in the same order as the custodian, you can use the same array index to separate the location string.  If the data might be in a different order, you are SOL unless you can match on custodian name.

Once you have the data properly normalized, you can mush it all together again if you must to export it but for your own purposes, keep it separate.
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 1000 total points
ID: 40487811
place this function in a regular module

Function ParseInfo(strNames, strPath) As String
Dim j, arrNames() As String, arrPath() As String, strResult As String
arrNames = Split(strNames, ";")
arrPath = Split(strPath, "|")

For j = 0 To UBound(arrNames)
    strResult = strResult & ";" & arrNames(j) & "::" & arrPath(j)
Next
ParseInfo = Mid(strResult, 2)
End Function


then create a query likethis

select  Custodian,Location, ParseInfo([Custodian],[Location])
From yourTable
0
 

Author Closing Comment

by:lauriecking
ID: 40609200
Thank you for your input. Both were very helpful.
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question