 | NOTE This is a draft and will be edited in the near future. This process has worked in the past, but is not yet something we are comfortable calling a Best Practice. |
Importing Connections from a Non-Metrix Source
The Process
Connections are not part of the Import Wizard. The data structure of Connections is rather complex, in that there are two records required for every Connection (a parent record and a child record), and there are fields in the table that refer to other records in the Connections table. Study tblConnections for a bit to make sure you have a sense of what data are stored there. You can get technical information about the table in our Data Dictionary
. This method adds these two types of records (parent and child) in batches.
This method was developed while working with a complex build--about 8,000 contacts and 25,000 connections! The original data was in a format quite different from what we needed for Metrix, so the first step was to whip the data into shape--a worksheet that had ContactID and then a field for each of the different Connection types the organization had. Here are the first few records from that table, after importing into an mdb. Getting it into this format does take quite a while, but it allows you to be systematic about creating the Connections, which hopefully means that others will be able to use this process. (Actually, this table only shows a few of the Connection types. In reality there were 12.)
| SandboxID |
tmpContactID |
RealContactID |
ContactRecordType |
Flag |
Org-OrgID |
Student-StudentID |
Student-School |
Student-Teacher |
Teacher-School |
Vol-OrgID |
| 2762 |
9369 |
|
Individual |
Student |
|
S-10380 |
es |
Smith |
|
|
| 2818 |
14572 |
|
Individual |
Student |
|
S-15763 |
ES |
Jones |
|
|
| 2954 |
4055 |
|
Individual |
Student |
|
S-4618 |
|
Wallace |
|
|
| 2955 |
4077 |
|
Individual |
Student |
|
S-4642 |
|
Mitchell |
|
|
| 2956 |
4196 |
|
Individual |
Student |
|
S-4786 |
|
Drakes |
|
|
Another trick is to modify tblConnections. Copy tblConnections from the Metrix back end to the mdb and then follow these instructions:
- Change the name of the ConnectionID field to PKey--this will be the autonumber field.
- Add a new field called ConnectionID--this is the field we update in the operations below.
- Copy the table to a new table called "Connections", but only copy the structure, not the data. This makes sure that your autonumber field starts at 0--not necessary, but it makes it easier to sanity check your data.
Once it is in this format and imported to the mdb, you'll have to build a series of update queries, and write some code to run the queries in the appropriate order (or just use the code included here, if you match our naming conventions). Doing it like this (and making backups) enables you to run through the process a bunch of times to make sure you are getting the results you need.
Sample Query List
Below is the list of queries from the build on which this was first developed. Starting with qryAlternateToStudent1Front you can see that there are two queries per connection type. The first three queries are different--one or two of them get run after each of the other queries, adding the reciprocal IDs and connection IDs. First we'll walk you through the code and then we can take a look at some of the individual queries.

The Code
Here's the basic process (this happens for each Connection type):
- Insert, into a modified copy of tblConnections, the parent records for one type of Connection.
- Update the ConnectionID for those records (based on an autonumber field in my copy of tblConnections).
- Insert the child records for that same type of Connection, including the ReciprocalID, taken from the parent records added in the first step.
- Update the ReciprocalIDs in the child records, using the ConnectionIDs in the parent records.
- Update the ConnectionIDs in the child records, using the ReciprocalIDs in those same child records.
Here's the code that calls all of the queries:
The Queries from one Connectin Type
Below are the SQL strings of the queries run to build one Connection type. Note that there are five of them:
- Build the "parent" records.
- Update the ConnectionID for those records.
- Insert the child records.
- Update the ReciprocalIDs in the child records.
- Update the ConnectionIDs in the child records.
Here's the SQL of one of the "parent" queries, qryStudentSchool1Front:
The Sandbox table is the table shown above. If the record represents a student, the field "Student-School" holds the name of that student's school. If the record represents a school, the field "ContactName" holds the name of the school. By linking two copies of the table to each other, on these two fields, we link the student to his or her school. The query then inserts a row in Connections to represent the parent side of this connection.
Once that is run, the code runs a1SetRecipInOrig. The SQL for that is:
This updates the ConnectionID field, based on the PKey field.
Next the code runs the "child" query for this connection type. In this case it's qryStudentSchool2Back:
Now the code runs two more queries, a2SetRecipInRecip and a3SetConnInRecip.
Here's a2SetRecipInRecip:
And here's a2SetRecipInRecip:
Moving the Data Back to Metrix
Now it's time to get the data back into tblConnections in the Metrix back end.
This portion of the process needs more thorough documentation, which will come shortly. In the original build, I believe I simply linked to the tblConnections in the mdb, from the Metrix back end and then ran an insert query from that linked copy to the live tblConnections, though there were, I think, some hoops to jump through on this, because of the Identity field.