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

How do I parse a string response into a temporary table? MS Access 2007/10 VBA

Hi,

I thought it would be good to post this as the service at www.getaddress.io seems a good one and the results may be of use to other access users.

I have just started using a free account from "getaddress" to see if this can be used to populate address fields within an access database.

It is relatively simple to set up and use the account.
A request is sent to the web service with a specific postcode attached to the request string.

In this example I sent the postcode SY186BN

The response string is as follows:

{"Latitude":52.448386,"Longitude":-3.540556,"Addresses":["Arcadia, 6 Great Oak Street, , , , Llanidloes, Powys","Bistro Hafren, 2 Great Oak Street, , , , Llanidloes, Powys","D'Eco, 4 Great Oak Street, , , , Llanidloes, Powys","Flat 1-2, 2 Great Oak Street, , , , Llanidloes, Powys","Ingrams, 3 Great Oak Street, , , , Llanidloes, Powys","Llanidloes Town Council, Town Hall, Great Oak Street, , , Llanidloes, Powys","Milwyn Jenkins & Jenkins, Mid Wales House, Great Oak Street, , , Llanidloes, Powys","The Kitchen, 5 Great Oak Street, , , , Llanidloes, Powys","Town Hall, Great Oak Street, , , , Llanidloes, Powys"]}

The data I am interested in initially is the list of addresses each with 7 fields which is enclosed between the square brackets []
The above example has 9 records of seven fields.
The number of records will vary but the number of fields within each record will be the same even if many of them are null.

What I need to achieve is the best way to take the response string and with it populate a table with the 7 data fields * no of records. The table will already be created so this does not need to be done programmatically.

TblAddrTemp:
Fields:
AddrTempID
TempAddr1
TempAddr2 etc to TempAddr7

I am fairly adept at VBA and SQL so once I have the data in a temp table I should be able to devise ways to use it to populate the main address tables fairly easily.

What I am not so good at (yet!) is complex text handling/parsing.

Any help much appreciated.
Jan 15 '16 #1

✓ answered by Seth Schrock

Here is the string parsing part of it. I just have Debug.Prints instead of writing to a table though.
Expand|Select|Wrap|Line Numbers
  1. Public Sub ParseString()
  2. Dim strReturnString As String
  3. Dim intStart As Integer
  4. Dim intLength As Integer
  5. Dim strInside As String
  6. Dim strRecords() As String
  7. Dim i As Integer
  8.  
  9. strReturnString = "{""Latitude"":52.448386,""Longitude"":-3.540556,""Addresses"":[""Arcadia, 6 Great Oak Street, , , , Llanidloes, Powys"",""Bistro Hafren, 2 Great Oak Street, , , , Llanidloes, Powys"",""D'Eco, 4 Great Oak Street, , , , Llanidloes, Powys"",""Flat 1-2, 2 Great Oak Street, , , , Llanidloes, Powys"",""Ingrams, 3 Great Oak Street, , , , Llanidloes, Powys"",""Llanidloes Town Council, Town Hall, Great Oak Street, , , Llanidloes, Powys"",""Milwyn Jenkins & Jenkins, Mid Wales House, Great Oak Street, , , Llanidloes, Powys"",""The Kitchen, 5 Great Oak Street, , , , Llanidloes, Powys"",""Town Hall, Great Oak Street, , , , Llanidloes, Powys""]}"
  10.  
  11. intStart = InStr(strReturnString, "[""") + 2
  12. intLength = InStr(strReturnString, """]") - intStart
  13.  
  14. strInside = Mid(strReturnString, intStart, intLength)
  15.  
  16. strRecords = Split(strInside, """,""")
  17.  
  18. For i = 0 To UBound(strRecords)
  19.     Debug.Print
  20.     Debug.Print "Record " & i + 1
  21.     Debug.Print "Field 1: " & Split(strRecords(i), ",")(0), _
  22.                 "Field 2: " & Split(strRecords(i), ",")(1), _
  23.                 "Field 3: " & Split(strRecords(i), ",")(2), _
  24.                 "Field 4: " & Split(strRecords(i), ",")(3), _
  25.                 "Field 5: " & Split(strRecords(i), ",")(4), _
  26.                 "Field 6: " & Split(strRecords(i), ",")(5), _
  27.                 "Field 7: " & Split(strRecords(i), ",")(6)
  28. Next
  29.  
  30. End Sub

4 1190
Seth Schrock
2,965 Expert 2GB
My first thought would be to us the InStr() function to find the location of the [" at the beginning and then the "] at the end, and then calculate the difference between these two points, which gets you the length of the text you care about. Then use the Mid() function to parse out the section using the information gathered above. You can then use the Split() function, using "," as delimiter, you will then have an array of each record. You can then loop through each element of this array and again use the Split() function using the , as the delimiter and you will then get the individual fields for each record. In your loop you can then write your information to the table.
Jan 15 '16 #2
Thanks Seth, that gives me a starting point. I'll post the code if I come up with anything that looks like it has a chance of working.
It might take me some while!
Meanwhile if anyone has some aircode I can play with I would much appreciate it as I've never had to tackle this kind of string manipulation before.
Jan 15 '16 #3
Seth Schrock
2,965 Expert 2GB
Here is the string parsing part of it. I just have Debug.Prints instead of writing to a table though.
Expand|Select|Wrap|Line Numbers
  1. Public Sub ParseString()
  2. Dim strReturnString As String
  3. Dim intStart As Integer
  4. Dim intLength As Integer
  5. Dim strInside As String
  6. Dim strRecords() As String
  7. Dim i As Integer
  8.  
  9. strReturnString = "{""Latitude"":52.448386,""Longitude"":-3.540556,""Addresses"":[""Arcadia, 6 Great Oak Street, , , , Llanidloes, Powys"",""Bistro Hafren, 2 Great Oak Street, , , , Llanidloes, Powys"",""D'Eco, 4 Great Oak Street, , , , Llanidloes, Powys"",""Flat 1-2, 2 Great Oak Street, , , , Llanidloes, Powys"",""Ingrams, 3 Great Oak Street, , , , Llanidloes, Powys"",""Llanidloes Town Council, Town Hall, Great Oak Street, , , Llanidloes, Powys"",""Milwyn Jenkins & Jenkins, Mid Wales House, Great Oak Street, , , Llanidloes, Powys"",""The Kitchen, 5 Great Oak Street, , , , Llanidloes, Powys"",""Town Hall, Great Oak Street, , , , Llanidloes, Powys""]}"
  10.  
  11. intStart = InStr(strReturnString, "[""") + 2
  12. intLength = InStr(strReturnString, """]") - intStart
  13.  
  14. strInside = Mid(strReturnString, intStart, intLength)
  15.  
  16. strRecords = Split(strInside, """,""")
  17.  
  18. For i = 0 To UBound(strRecords)
  19.     Debug.Print
  20.     Debug.Print "Record " & i + 1
  21.     Debug.Print "Field 1: " & Split(strRecords(i), ",")(0), _
  22.                 "Field 2: " & Split(strRecords(i), ",")(1), _
  23.                 "Field 3: " & Split(strRecords(i), ",")(2), _
  24.                 "Field 4: " & Split(strRecords(i), ",")(3), _
  25.                 "Field 5: " & Split(strRecords(i), ",")(4), _
  26.                 "Field 6: " & Split(strRecords(i), ",")(5), _
  27.                 "Field 7: " & Split(strRecords(i), ",")(6)
  28. Next
  29.  
  30. End Sub
Jan 15 '16 #4
That works a treat. Many thanks you've saved me hours of headache time!!
Jan 15 '16 #5

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

Similar topics

0
by: Didier ROS | last post by:
Hi, I am a newbie I want to create a temporary table and I get the following error message : mysql> CREATE TEMPORARY TABLE tempemp AS SELECT * FROM emp; ERROR 1044: Access denied for user:...
9
by: Python.LeoJay | last post by:
Dear all, i need to parse billions of numbers from a file into float numbers for further calculation. i'm not satisfied with the speed of atof() function on my machine(i'm using visual c++ 6)....
49
by: Allen Browne | last post by:
If you are looking for opinon on what's useful in Access 2007, there's a new article at: http://allenbrowne.com/Access2007.html Covers what's good (useful features), what's mixed (good and bad),...
2
by: thepisu | last post by:
Does anyone knows the odbc driver / string to connect to Access 2007 file (.accdb)? I can't find it anywhere...
0
by: Franck | last post by:
Hi, Got some problems from reading temporary table I'm creating in my Sql Server 2005 Database from Access 2K3 through ODBC. I can create it successfully but can't find a way to query it ! The...
1
by: blademike | last post by:
Hi guys, I'm new to Access & SQL. Currently using Access 2007. What I have: 1) Table: Employee( empID, empName, email, pwd, ... ) 2) Form: - Record source ( SELECT empName, email, pwd FROM...
0
by: Accessed | last post by:
Using Access 2007 to work on Access version 2003 database. Part of the process creates a temporary database using the createdatabase method, then links to a table in that temporary database. ...
6
by: tony.abbitt | last post by:
I have recently installed Office 2007 (SP1) retaining the previous installation of Office 2003. I have converted an Access 2003 database to Access 2007. The database contains the VBA code...
0
by: Seun Oguntomini | last post by:
Hi, How are you and work? Pls am a user of Microsoft Access 2007. There is need for me to enter multiple words in a field in MS Access 2007 which am finding it difficult to do For me to be able...
1
by: JD79 | last post by:
I have an access 2007 database (on an XP machine) that extracts a large set of data from an Oracle db using ODBC. The data extraction is done with a dynamic passthru query that is then called in a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.