2007到2010转换编译错误:未定义用户定义的类型

时间:2013-07-23 14:30:12

标签: ms-access-2010

我最近将2007 Access文件转换(导出/导入)到2010.除了一个表单外,一切正常。我一直收到错误“编译错误:用户定义的类型未定义”

我尝试将“Microsoft ActiveX Data Objects 2.8”添加到我的参考文献中,但问题仍然存在。对问题可能是什么的任何想法?我是一个不成熟的人,我没有写这个代码,但现在是。粗体文本是Access突出显示的问题。非常感谢提前!

选项比较数据库 选项明确

'清除树视图控件上的所有节点 Sub ClearTreeView(tvwTree As TreeView)     在错误GoTo EH     tvwTree.Nodes.Clear     退出子 EH:     MsgBox“错误”& Err.Number& “:”& Err.Description 结束子

'调用函数来清除和填充树视图控件 '参数: 'strForm表单的名称 'strTV TreeView控件名称 'strSourceName包含用于填充树视图的数据的表或查询的名称 '子记录的strChildField ID字段 'strParentField父ID字段 'strTextField字段,包含将用作节点标签的文本 “ Sub FillTreeView(tvwTree As Object,strSourceName As String,strChildField As String,strParentField As String,strTextField As String)     Dim strSQL As String     Dim rs As DAO.Recordset

On Error GoTo EH

' Open the recordset using table and fields specified in Sub parameters
strSQL = "SELECT " & strChildField & ", " & strParentField & ", " & strTextField & " FROM " & strSourceName
Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)

' Clear any existing data out of the treeview
ClearTreeView tvwTree

' Call recursive function to fill in treeview
AddTreeData tvwTree, rs, strChildField, strParentField, strTextField

' Close the recordset
rs.Close
Set rs = Nothing
Exit Sub

EH:     MsgBox“错误”& Err.Number& “:”& Err.Description 结束子

'用于填充树视图控件的递归函数 '参数: 'strFormName表单的名称 'strTreeViewName TreeView控件名称 'rs Recordset包含用于填充树视图的数据 '子记录的strChildField ID字段 'strParentField父ID字段 'strTextField字段,包含将用作节点标签的文本 'varParentID可选参数,仅传递给此函数的递归调用。指定要用作的当前记录的ID '搜索记录集中的“孙子”等时的ParentID Sub AddTreeData(objTV As TreeView,rs As DAO.Recordset,strChildField As String,strParentField As String,strTextField As String,optional varParentID As Variant)     Dim nodChild As Node     Dim nodParent As Node     Dim strLabel As String     Dim strNodeID As String     将strCriteria作为字符串     Dim strBookmark As String

On Error GoTo EH

' Test for a circular reference
If rs(strChildField) = rs(strParentField) Then GoTo EH_CircularReference

' If the optional parameter is missing, then this is the first(non-recursive) call to this function.
' Set the critieria to look for a parent id of 0.
If IsMissing(varParentID) Then
    strCriteria = strParentField & " = 0 "
Else
    ' Otherwise, extract the childID portion of the node ID, which was passed as an optional parameter.
    strCriteria = strParentField & " = " & Mid(varParentID, InStr(1, varParentID, "C") + 1)
    ' Define the parent node
    Set nodParent = objTV.Nodes("node" & varParentID)
End If

' Look for records having the specified "parent"
rs.FindFirst strCriteria
Do Until rs.NoMatch
    ' Read node caption from the text field
    strLabel = rs(strTextField)
    ' Create a new node ID in the format ParentID &"C" & ChildID (eg: 4C12)
    strNodeID = "node" & rs(strParentField) & "C" & rs(strChildField)

    ' If optional parameter is missing (first call to this function)...
    If Not IsMissing(varParentID) Then
        'add new node to the next higher node for this record
        Set nodChild = objTV.Nodes.Add(nodParent, tvwChild, strNodeID, strLabel)
    Else
        ' Otherwise, add new node to the top level of the tree
        Set nodChild = objTV.Nodes.Add(, , strNodeID, strLabel)
    End If

    ' Bookmark our place in the recordset so that we can resume the search from the same point after the recursive call to this function.
    strBookmark = rs.Bookmark

    ' call this function recursively for "children"
    AddTreeData objTV, rs, strChildField, strParentField, strTextField, rs(strParentField) & "C" & rs(strChildField)

    ' Return to bookmared place in the recordset
    rs.Bookmark = strBookmark

    ' Find the next record having the same parentID
    rs.FindNext strCriteria
Loop

Exit Sub

EH_CircularReference:     MsgBox“由于循环引用而退出,其中子记录被确定为它自己的父级。”     退出子

EH:     MsgBox“错误”& Err.Number& “:”& Err.Description 结束子

1 个答案:

答案 0 :(得分:3)

我在Excel中的一个用户表单上收到了同样的错误!

如果您的新2010 Office软件包是64位,则2007版本中使用的以前的32位ActiveX控件将不兼容。

请参阅此链接:http://msdn.microsoft.com/en-us/library/ee691831(office.14).aspx#odc_office2010_Compatibility32bit64bit_ActiveXControlCOMAddinCompatibility

如果您尝试在设计视图中打开表单并且表单上不存在TreeView控件,那么这可能就是问题所在。

要查找您是否安装了64位版本: 开放存取 - >档案 - >帮助 - >并查看右侧的“关于Microsoft Access” - 它应该是括号中的32位或64位

如链接所述,您必须更换不兼容的功能 - 因此您必须使用新控件。

可能的解决方案:

如果您在设计视图中打开表单,并在功能区选项卡中选择控件组上的向下箭头 - 应该有一个名为“ActiveX控件”的选项(您必须在设计视图中选择它)

在此处搜索“CTreeView”控件并尝试使用它而不是传统的Microsoft TreeView控件(不应在64位访问中列出)。

如果您安装了32位办公室,那么我无法弄清楚您发布的内容的问题 - 但我怀疑是这种情况。

最诚挚的问候,