The Situation
I maintain a legacy MS-Access database which is used to manage the contacts to a set of doctors offices. Initially the table "offices" (old) included information about the office and the employed doctors like this (abbreviated):
| office | street | number | postcode | city | name1 | surname1 | name2 | surname2 | name3 | surname3 |
|---|
An office could have between 1 and 3 doctors.
Initial Steps
A new requirement came up which asked for the separate modelling of offices and doctors as a 1:n Relationship.
I created a new table doctors:
| name | surname | office_id |
|---|
transformed the underlying data, dropped the redundant fields from the "office"-table and am now in the process of modifying the buisness logic accordingly.
First idea: Elegant or lazy? It fails any way
My first impulse was to create an "office" view which recreated the old "office" table and change the references to the "old" office table to this "office" view. This way I could keep the logic as it is and only adjust as needed.
The problem was, that the "office" table is very fundamental and used all over the place and i didn't manage to recreate the table without writing my own functions using a cursor making the view very costly. That the database is used in a Network environment didn't help because although this worked in principle, the .accdb file blows up to 70 to 80mb resulting in massive load times, making it in effect unusable.
Lets do it properly
So I ditched the "office" view and reworked the database to employ the new data model. A MailMerge Letter is given me particular trouble and i haven't found a good solution yet. The DataSource for the MailMergeDocument is a View relying basicly on the data in the "offices" and "doctors" table.
The issue
previously the Address field in word just used this as a datasource
| id | street | postcode | city | name1 | surname1 | name2 | surname2 | name3 | surnname3 |
|---|---|---|---|---|---|---|---|---|---|
| 3 | Mainstreet | 01234 | timbuktu | Doe | John | Mae | Jane | Bar | Foo |
Now i have an 1:n relationship and the datasource looks like this:
| office_id | street | postcode | city | surname | name |
|---|---|---|---|---|---|
| 3 | Mainstreet | 01234 | timbuktu | John | Doe |
| 3 | Mainstreet | 01234 | timbuktu | Jane | Mae |
| 3 | Mainstreet | 01234 | timbuktu | Foo | Bar |
However i still need to get all 3 (or in other cases just 2 or 1) Doctors on the adress field and yes there can be more than 1 office listed in the datasource.
Possible Solutions
I see basicly 2 Options:
- Transform the view back into the previous format, without using Custom Functions, making it costly again, using a Single SQL-Statement.
- Using the field functions within the word document to skip through the records as needed. In theory the Nextif-function should do exactly that, however i haven't been able to figure out how and if I can evaluate Data between different records in the word document. I need something like:
Nextif nextrecord.id = currentrecord.id
but i havent found a way to reference the records whithin the fieldfunctions.
Any suggestions for a clean solution are welcome.
Regards