Developer Documentation Library > Data Model > Accessing the UNICOM Intelligence Data Model > Working with the Metadata Model > Working with metadata versions > Working with multiple versions
 
Working with multiple versions
You are not restricted to accessing a single version of the metadata and can access multiple versions simultaneously. When you do this, the versions are combined to form a superset (sometimes called a superversion). When there is a conflict between, for example, a text in one or more of the versions, the more recent versions generally take precedence over the older versions. However, you can optionally specify the order of precedence. You typically use a superversion when you want to export or analyze response data that has been collected using more than one version of the questionnaire.
You use a version expression to specify the versions you want to access and the order of precedence that you want to use. For example, you can use a version expression to specify multiple versions as a parameter of both the Document.Open method and the Document.CurrentVersion property (see IDocument.Open and IDocument.CurrentVersion in the MDM Object Model Reference). For more information, see Version expressions.
The Document object has two properties that are useful when you are creating applications that work with multiple versions:
Document.SelectedVersions. This stores the names of the currently selected versions. This means that consumer applications do not need to parse the version expression. See also IDocument.SelectedVersions in the MDM Object Model Reference.
Document.VersionSets. This has been designed for use by consumer applications to store the version expressions that have been used, so that they can be reused easily. See also IDocument.VersionSets in the MDM Object Model Reference.
Both of these properties are also available on the Document.Info object. This means, for example, that before you open an .mdd file, you can easily get a list of the version expressions that have previously been used with it.
When you are analyzing case data that was collected using multiple versions, you might want to use the version number in your crosstabulations. Provided system variables are enabled, you can request a derived categorical variable that automatically has a category for each version that is selected. For example, if you open versions 1, 2, 3, 4, and 5, the variable will have five categories, one for each version. Here is a crosstabulation that uses the new derived variable:
Table of metadata versions by Gender
This graphic is described in the surrounding text.
The derived variable is called DataCollection.MetadataVersion and you request it using the Document.EnableMetadataVersionVariable property. To avoid potential problems during exports, neither the derived variable nor the setting that requests it are persisted in the Document when it is closed. This means you need to set the property whenever you want to use the derived variable.
The following mrScriptBasic example shows how to do this. The example uses the Short Drinks sample data set to set up the crosstabulation in Word.
Dim MyDocument, sqlQuery
Dim ConnectionString, DataLinkHelper, adoConnection, adoRS
Dim wordApp, wordDoc

Const MDDFILE = "C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Data\Mdd\short_drinks.mdd"

Set MyDocument = CreateObject("MDM.Document")
' Open all versions of the Short Drinks sample in read-only mode
MyDocument.Open(MDDFILE, "{..}", MDMLib.openConstants.oREAD)

' Request the metadata version derived variable
MyDocument.EnableMetadataVersionVariable = True

' Setup an ADO connection to the open Short Drinks Document
Set DataLinkHelper = CreateObject("MROLEDB.DataLinkHelper")
ConnectionString = "Provider=mrOleDB.Provider.2;MR Init Category Names=1;MR Init MDM Document=" + _
DataLinkHelper.CreateDocumentObjectString(MyDocument)

Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Open(ConnectionString)

' Execute a SQL query against the Short Drinks vdata table
sqlQuery = "SELECT DataCollection.MetadataVersion As Version, " + _
"SUM(gender = {male}) AS Male, SUM(gender = {female}) AS Female " + _
"FROM vdata WHERE DataCollection.MetadataVersionNumber IS NOT NULL " + _
"GROUP BY DataCollection.MetadataVersion"
Set adoRS = adoConnection.Execute(sqlQuery)

' Create a Word document
Set wordApp = CreateObject("Word.Application")
Set wordDoc = wordApp.Documents.Add()
wordApp.Visible = True

' Write the result set from the SQL query to
' the Word document
With wordDoc.ActiveWindow.Selection
.Text = "Metadata versions by Gender"
.Font.Name = "Arial"
.Font.Size = 10
.Font.Bold = True
.MoveDown()
.TypeParagraph()
.Font.Size = 8
.TypeParagraph()
.Text = "Version" + mr.Tab + _
MyDocument.Fields["gender"].Elements[0].Label + _
mr.Tab + MyDocument.Fields["gender"].Elements[1].Label
.ConvertToTable()
.MoveDown()
.Font.Bold = False
If Not adoRS.EOF Then
Do Until adoRS.EOF
' Copy the RecordSet into Word
.Text = adoRS.GetString()
.ConvertToTable()
.MoveDown()
.TypeParagraph()
If Not adoRS.EOF Then
adoRS.MoveNext()
End If
Loop
End If
End With

adoConnection.Close()

wordDoc.SaveAs("C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Output\metadata_versions.doc")
wordApp.Quit()
Because you need to request the variable at runtime, this example opens the Document, sets the flag, and then uses the DataLinkHelper.CreateDocumentObjectString to create a string representation of the Document pointer that can be used when connecting to the case data using ADO. For more information, see Connecting using an open MDM document. However, in Data Model 2.8 and later you can request the variable by using the MR Init MDM Version Variable connection property. For more information, see Connection properties.
See also
Working with metadata versions