Reputation: 1497
I have a form in MS-Access which shows tabular data. as follows
record id record date record content
--------- ----------- --------------
1 1/2/2011 name: ben, age:38, sex: M; name: emma, age:32, sex: F
2 5/5/2012 name: john, age:28, sex: M; name: eva, age:24, sex: F
There is no limit in how many people's records can be there in each record content cell. but each record will have only those 3 fields. Name, Age and Sex.
I need to split the record content in a subform such a way that it looks like:
record id record date record content
--------- ----------- --------------
1 1/2/2011 name age sex
---- --- ---
ben 38 M
emma 32 F
2 5/5/2012 name age sex
---- --- ---
john 28 M
Eva 24 F
What is the easiest way to achieve this? The table from where the record is coming has the data in similar format as shown in the first diagram. How can I split this compound string and display it in multiple rows?
Upvotes: 0
Views: 1306
Reputation: 11607
You need to normalise your data--split the source table up into two.
(How? You need to write some VBA code to:
this regular expression will probably get you the name, age and sex out of the string as the first, second and third matched items:
"^.*name:\s*([^,]+),\s*age:\s*([^,]+),\s*sex:\s*([.*])$"
after doing the regex match you grab the matched items, put them into name, age and sex variables, and use these values and the record id you saved earlier to insert into the new People table.)
Tables:
ID
RecordID - references Records.ID
PersonName
Age
Sex
ID
RecordDate
After that you can use a sub-form within your current main form to display the people associated with each record. Access makes that pretty easy if you have a parent-child relationship between two tables, as you do above.
Upvotes: 2