Transform csv file to match access table for import

standenman

Member
Local time
Yesterday, 20:23
Joined
May 12, 2016
Messages
45
I have created a form in JotForms in which my clients can input details about the medications they are currently taking (name, dosage, side effects, etc). So any given client could be taking 1 or 20 medications. This would correspond to a table in my Access DB, tblMedications where each medication is a new record, with a CllientID field to associate it with the right client.

So with JotForms I find I can export to excel. When I do that I get only two rows: a column heading and the second being the data. Rather than creating a row for each medication, it appears that every medication has a number in its header text like this:

Please List All Medications You Are Currently Taking >> 1 >> Medication Name


Below this column header we would have , "Prozac" or "Methocarbomol", the name of the medication. These types of column headers continue with same format: "Text instruction to user on the JotForm" >> Number corresponding to what should be a row >> What should be the Column Header that would correspond to field name in Access table.

So what I need is the number to correspond to a row, and the text that follows a column name. So here this is the first medication, and if I had a "2" it would be the second medication. And it belongs in a column titled "Medication Name". Can anyone help?
 

Attachments

Hi and welcome to AWF!

First can we take a step back and just check your table design on the Access side.

What you describe would normally be a many-to-many relationship, with a clients table, a medications table (listing each unique medication) and a junction table between the two with ClientID and Medication ID to hold which clients take which medications.

Is this what you have?
 
Presume this is a cross post from here
Please provide an example of the csv file (not excel, once excel gets its hand on it it can change things) plus a screenshot of your relationships indicating which tables you want to import to

edit: zip the csv file before uploading
 
As suggested in your post on the other forum you can parse out the csv file using VBA or probably easier you can import it in a temporary Access table that matches the current layout (you have actually 25 not 20 sets of fields for the medication) then use VBA or a set of (25) append queries to "transpose" each set of fields to new rows.

Cheers,
 
Presume this is a cross post from here
Please provide an example of the csv file (not excel, once excel gets its hand on it it can change things) plus a screenshot of your relationships indicating which tables you want to import to

edit: zip the csv file before uploading

Also here

 
As mentioned in a previous response, you will first have to get the structure of the database in order.
Based on the structure of the csv file, I arrive at the following database structure.
medication2.jpg
 
OP said he 'got it' regarding cross posting, 'getting' and 'doing' seem to be two different things in the OP's book.
 
The shame is that there are plenty of folk willing and eager to help you, Stan, but you don't answer any of the questions asked of you which would help guide the answers/suggestions we could make, or report back on how any suggestions made worked/didn't work for you etc.
 
The shame is that there are plenty of folk willing and eager to help you, Stan, but you don't answer any of the questions asked of you which would help guide the answers/suggestions we could make, or report back on how any suggestions made worked/didn't work for you etc.
Not true! wow, what attitude here.
 
Not true! wow, what attitude here.
Whatever.

I asked a simple question in response to your original post and received no reply.

Vlad makes a suggestion in Post #4 and has received no feedback as to whether this could work for you.

Peter makes a suggestion in Post #6 - again no response.

And now you're having a go at me! <shrug>
 
Amazing. I have marked the post as solved yet the pot shots keep coming.
 

The article suggests that there is a way to export from Jotform to Excel but there is no direct way to interact with Access. Which is why they suggest an Access import as a second step. The problem here is compounded by the fact that you get a LOT of columns back if someone is taking lots of different meds. If you get more than 255 columns, you are sunk for direct import because Access has a limit of 255 fields but Excel does not have a limit of 255 columns.

Looking at your exhibits, I presume that your continuing issue as noted in the other thread is that the instructions from Jotform don't lead you to download something easily useful. From your exhibit "MEDICATION_LIST...", it would appear that the data has been linearized in a particularly ugly way. Let me ask this, though. If you downloaded the file to Excel CSV format, would it actually have data in the 2nd row instead of just headers? I'm trying to break down what you actually get because the required transform here is definitely non-trivial. The first step will be to understand the "before" so that we could figure out a path to an "after."

In essence, this is the kind of thing that would take some Access programming AND some Excel Application Object programming. In rough terms, what SHOULD have been a parent/child table got flattened. Which unfortunately is not unexpected since Excel is basically a flat-file format with some window dressing. It would take some serious VBA work to decipher the stuff you have to work with and separate out the parent records from the embedded (linearized) child records.

I can show you the way, but I have to ask: Before heading down that rabbit hole, how far do you want to go, knowing that you will have some complex VBA to work through? I can guide you but you will have work to do too.
 
Thanks very much for your comments and attention. I think I am at a crossroad here: stay with Access or either buy or create a more specific case management system. The most obvious concern - which as kept me tethered to Access - is the difficulty of migrating my data. There seem to signs, however, that Microsoft is neglecting Access, such as doing away with some type of webform, which would have been helpful here perhaps. I am going to table this inquiry in the coming weeks as a explore my options.
 
The Access webforms weren't useful because they tethered you to SharePoint which everyone hated and they did not provide an actual programming language and working with macros is limiting.

Access is a mature development platform. There are millions of Access applications out there that depend on it and require stability. Therefore, don't expect MS to be adding shiny new things to Access but also don't think they won't do any development.

I dropped out of the thread early because questions asked by the experts didn't get answered and the cross-posting just wastes our time.

PS, maybe it is your thread in the other forum that you marked as Solved.
 
That is, of course, your choice. It is regrettable but true that M$ appears to blow hot and cold at different times. I think their problem is that Access grew TOO popular in the scheme of things, perhaps because someone hasn't thought things through - and because their design was self-limiting in a way that they didn't originally anticipate. That self-limiting design was what eventually killed the ADP feature that would have supported a web form setup. Things didn't start well here, but that doesn't stop the fact that you have an issue to be resolved. I can get past the rocky start if you can.

The bigger issue is a non-trivial one of a complex ... I'll call it a "deconvolution" ... related to unflattening a flattened file. If you cannot find your way to something more helpful in the future, come back to this thread and click the "Reply" in the lower right corner. As a reply, it will alert me.

So that I will remember the method I figured out and not have to re-research it, I will offer a couple of notes on the approach so that if you decide to come back later, I'll recall what I saw and can restart faster. Or, others seeing this could pick it up as well.

The Jotform output appears to be essentially an enumeration of every field, with the field identifying information stored linearly in the name row. The solution would be to scan the name row as text data to decide where the associated information from the same column in the data row would go. For the things that would go into the person table, the titles are fairly clear. There is a pattern to the columns that correspond to the child table information and the titles would help identify that part as well. By using something like the SPLIT function, it should be possible to extract the child row number and the correct field name for each child entry. Because of the possibility that the Excel data would exceed 255 columns, the direct import would not be possible, but a loop to decipher it "on-the-fly" directly from Excel might do the trick. The only question remaining is how much data appears in one such file, in terms of how many PERSONS would be represented (how many data rows).

The algorithm would be to use an Excel Object to open the .CSV file and step through the columns. I'm assuming that the data would be starting in row 2 with those ugly titles in row 1. On the Access side, open recordsets - one for the person and one for the meds plus one more for the junction table that would be the ideal way to store this dataset. It would parallel the first of your two JPG offerings in post #1. Stepping by columns, read the header row and then decipher the table field to which it corresponds and in each case, store the content of the data row in the field identified from the column names.

The first several columns represent the person's data. You would eventually, if I read the layout right, reach the first record that is child data and recognize it by the "Please enter..." string. Stop there to save (rs.Update) the person data, which would allow you to retrieve an autonumber key if you were using that to identify persons. (Note: If you had a separate table of recurring clients, you could perform a lookup right here to decide if they already had a client number.)

Then continue your loop to populate the child table. By decomposing the titles and paying attention to the embedded number that is in the middle of each potential child entry title, you would know when you stepped to a new "line item" and could save the line you just accumulated. If you are doing the junction table, at this time you could also enter the data for the new junction record. When you finally reach the point where there is no data remaining as determined by blanks in a critical data element OR by having run out of row 1 titles, you are done with that person record. The next step depends on how many persons are represented in the import file. If there COULD be more persons, you would simply update the data row number and loop through the headers again.

IF you have multiple data rows for multiple people, the only trick is that you determine the end of the run by verifying that the data row has only blank cells remaining. If each file is a single person, you should run out of column headers at the same time you run out of data cells.

The structure of the loop would be based on (probably) a big SELECT CASE ladder selecting what to do with each field as it comes in. For most cases you would do nothing more than store the data element (or convert and store, if numeric) in a field in the open recordsets. For a few cases, you would manipulate the recordsets via .Update, and might also have to do minor maintenance on the "implied child record" number to know that you have started a new child row.

There, that is the approach that I would use in Access. If you find some other way, perhaps that will help you to design your response in that other environment. Good luck with that.
 
I again apologize for the "cross posting". If someone could suggest the appropriate penance I would do it so we could get this over with. I have a little dachsund I am growing tired of, would that work? (Kidding I love that frustrating little hound).

I am not exactly expecting "shiny things" from Access although perhaps I would like the ability to build them? At the heart, I guess, is the question: can Access be the basis of a reasonable "modern" case management system. The initial frustration with the seeming (to me) simple task of incorporating data into the DB from an online form suggest to me I am better off leaving Access behind.
 
That is, of course, your choice. It is regrettable but true that M$ appears to blow hot and cold at different times. I think their problem is that Access grew TOO popular in the scheme of things, perhaps because someone hasn't thought things through - and because their design was self-limiting in a way that they didn't originally anticipate. That self-limiting design was what eventually killed the ADP feature that would have supported a web form setup. Things didn't start well here, but that doesn't stop the fact that you have an issue to be resolved. I can get past the rocky start if you can.

The bigger issue is a non-trivial one of a complex ... I'll call it a "deconvolution" ... related to unflattening a flattened file. If you cannot find your way to something more helpful in the future, come back to this thread and click the "Reply" in the lower right corner. As a reply, it will alert me.

So that I will remember the method I figured out and not have to re-research it, I will offer a couple of notes on the approach so that if you decide to come back later, I'll recall what I saw and can restart faster. Or, others seeing this could pick it up as well.

The Jotform output appears to be essentially an enumeration of every field, with the field identifying information stored linearly in the name row. The solution would be to scan the name row as text data to decide where the associated information from the same column in the data row would go. For the things that would go into the person table, the titles are fairly clear. There is a pattern to the columns that correspond to the child table information and the titles would help identify that part as well. By using something like the SPLIT function, it should be possible to extract the child row number and the correct field name for each child entry. Because of the possibility that the Excel data would exceed 255 columns, the direct import would not be possible, but a loop to decipher it "on-the-fly" directly from Excel might do the trick. The only question remaining is how much data appears in one such file, in terms of how many PERSONS would be represented (how many data rows).

The algorithm would be to use an Excel Object to open the .CSV file and step through the columns. I'm assuming that the data would be starting in row 2 with those ugly titles in row 1. On the Access side, open recordsets - one for the person and one for the meds plus one more for the junction table that would be the ideal way to store this dataset. It would parallel the first of your two JPG offerings in post #1. Stepping by columns, read the header row and then decipher the table field to which it corresponds and in each case, store the content of the data row in the field identified from the column names.

The first several columns represent the person's data. You would eventually, if I read the layout right, reach the first record that is child data and recognize it by the "Please enter..." string. Stop there to save (rs.Update) the person data, which would allow you to retrieve an autonumber key if you were using that to identify persons. (Note: If you had a separate table of recurring clients, you could perform a lookup right here to decide if they already had a client number.)

Then continue your loop to populate the child table. By decomposing the titles and paying attention to the embedded number that is in the middle of each potential child entry title, you would know when you stepped to a new "line item" and could save the line you just accumulated. If you are doing the junction table, at this time you could also enter the data for the new junction record. When you finally reach the point where there is no data remaining as determined by blanks in a critical data element OR by having run out of row 1 titles, you are done with that person record. The next step depends on how many persons are represented in the import file. If there COULD be more persons, you would simply update the data row number and loop through the headers again.

IF you have multiple data rows for multiple people, the only trick is that you determine the end of the run by verifying that the data row has only blank cells remaining. If each file is a single person, you should run out of column headers at the same time you run out of data cells.

The structure of the loop would be based on (probably) a big SELECT CASE ladder selecting what to do with each field as it comes in. For most cases you would do nothing more than store the data element (or convert and store, if numeric) in a field in the open recordsets. For a few cases, you would manipulate the recordsets via .Update, and might also have to do minor maintenance on the "implied child record" number to know that you have started a new child row.

There, that is the approach that I would use in Access. If you find some other way, perhaps that will help you to design your response in that other environment. Good luck with that.
Wow, OK thank you so much for that information. That's a lot; I appreciate it.
 

Users who are viewing this thread

Back
Top Bottom