Hi..
I have this module which takes metadata out of SPSS and places it in an access table..
it brings over the variable names, labels, the value codes, and the labels for the codes..
the data is brought over in a seperate process..
the problem is that if the variable is a string then it only has a varname and varlabel no code... this is the same for a numeric variable with no coding...
this module only picks up those that have had coding put on them..
what it seems to do is look on the code column and then bring out the rest of the data... is there anyway to modify the routine below to search on the varname and then bring out the relevant data..
think I need to change the recordset to look on varname..rather than plabelcount....?
any ideas are very welcome...
Thanks
John
--------------------------------------------------------------------------------
' NOTE: In order to be able run this, you need to add the SPSS Type
Library to ACCESS using the
' following menu from MS Visual Basic for Access: Tools>References...
Option Compare Database
Option Explicit
Sub main()
' Parameters to GetSpssLab are
' 1) name of SPSS file and
' 2) name of ACCESS table which will contain the data.
' That table must contain the 4 field names: varname, varlabel, value
and vallabel
' before calling the Sub
Call GetSpssLab("c:\temp\ding.sav", "test")
End Sub
' This imports variable names, variable labels, values & value labels
' directly from an SPSS *.sav file.
' Source: Thomas.Zapf-Schramm@t-online.de newsgroup 2000/09/23
Sub GetSpssLab(spssfile As String, labtab As String)
Dim spssapp As spsswin.Application
Dim spssdat As spsswin.ISpssDataDoc
Set spssapp = New spsswin.Application
Set spssdat = spssapp.OpenDataDoc(spssfile)
Dim i As Long
Dim j As Long
Dim ret As Long, pNames As Variant, pLabels As Variant, pTypes As
Variant, pMsmtLevels As Variant, pLabelCounts As Variant
Dim pvalues As Variant, pvaluelabels As Variant
Dim nvars As Long
Dim ncodes As Long
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset(labtab, dbOpenDynaset)
On Error GoTo ErrExit
With spssdat
nvars = .GetVariableInfo(pNames, pLabels, pTypes, pMsmtLevels,
pLabelCounts)
For i = 0 To nvars - 1
ncodes = pLabelCounts(i)
If ncodes > 0 Then
ret = .GetVariableValueLabels(i, pvalues,
pvaluelabels)
For j = 0 To ncodes - 1
rs.AddNew
rs("VARNAME") = pNames(i)
rs("VARLABEL") = pLabels(i)
rs("VALUE") = pvalues(j)
rs("VALLABEL") = pvaluelabels(j)
rs.Update
Next
End If
Next
End With
ErrExit:
Debug.Print Err.Number; Err.Description
spssapp.Quit
rs.Close
End Sub
I have this module which takes metadata out of SPSS and places it in an access table..
it brings over the variable names, labels, the value codes, and the labels for the codes..
the data is brought over in a seperate process..
the problem is that if the variable is a string then it only has a varname and varlabel no code... this is the same for a numeric variable with no coding...
this module only picks up those that have had coding put on them..
what it seems to do is look on the code column and then bring out the rest of the data... is there anyway to modify the routine below to search on the varname and then bring out the relevant data..
think I need to change the recordset to look on varname..rather than plabelcount....?

any ideas are very welcome...
Thanks
John
--------------------------------------------------------------------------------
' NOTE: In order to be able run this, you need to add the SPSS Type
Library to ACCESS using the
' following menu from MS Visual Basic for Access: Tools>References...
Option Compare Database
Option Explicit
Sub main()
' Parameters to GetSpssLab are
' 1) name of SPSS file and
' 2) name of ACCESS table which will contain the data.
' That table must contain the 4 field names: varname, varlabel, value
and vallabel
' before calling the Sub
Call GetSpssLab("c:\temp\ding.sav", "test")
End Sub
' This imports variable names, variable labels, values & value labels
' directly from an SPSS *.sav file.
' Source: Thomas.Zapf-Schramm@t-online.de newsgroup 2000/09/23
Sub GetSpssLab(spssfile As String, labtab As String)
Dim spssapp As spsswin.Application
Dim spssdat As spsswin.ISpssDataDoc
Set spssapp = New spsswin.Application
Set spssdat = spssapp.OpenDataDoc(spssfile)
Dim i As Long
Dim j As Long
Dim ret As Long, pNames As Variant, pLabels As Variant, pTypes As
Variant, pMsmtLevels As Variant, pLabelCounts As Variant
Dim pvalues As Variant, pvaluelabels As Variant
Dim nvars As Long
Dim ncodes As Long
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset(labtab, dbOpenDynaset)
On Error GoTo ErrExit
With spssdat
nvars = .GetVariableInfo(pNames, pLabels, pTypes, pMsmtLevels,
pLabelCounts)
For i = 0 To nvars - 1
ncodes = pLabelCounts(i)
If ncodes > 0 Then
ret = .GetVariableValueLabels(i, pvalues,
pvaluelabels)
For j = 0 To ncodes - 1
rs.AddNew
rs("VARNAME") = pNames(i)
rs("VARLABEL") = pLabels(i)
rs("VALUE") = pvalues(j)
rs("VALLABEL") = pvaluelabels(j)
rs.Update
Next
End If
Next
End With
ErrExit:
Debug.Print Err.Number; Err.Description
spssapp.Quit
rs.Close
End Sub