Solved

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

Posted on 2014-12-08
3
213 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 38

Accepted Solution

by:
PatHartman earned 250 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 250 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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