【问题标题】:Extracting data from a Database that was built on access从基于访问的数据库中提取数据
【发布时间】:2016-12-19 20:54:01
【问题描述】:

如何使用 access 而不是它运行的 GUI 打开数据库?

您好,我正在尝试从基于访问但不使用访问运行的数据库中提取数据。这是一款名为“Gemma”的旧软件,由 Castle Personnel 早在 1999 年发布。他们不再为其数据库提供支持,我们作为一家公司正在尝试迁移到基于不同浏览器的在线数据库。

打开 Gemma 时,它不会通过 Access 打开,而是有自己的 GUI。当我打开数据库的位置时,它被保存为 .mdb 有一天我在玩这些文件,当我选择了一个数据库时,我点击了 shift enter。它在 Access 中打开了整个数据库,这显然让我可以访问所有数据。但是,这种方法似乎不再起作用了。

任何帮助将不胜感激

【问题讨论】:

标签: database ms-access


【解决方案1】:

只需启动 Access 的副本,然后打开有问题的数据库。正如您所注意到的,在大多数情况下按住 shift 键有效(但可以禁用)。 所以请注意我建议先打开 Access(不是通过单击 mdb 文件来启动访问,然后根据文件扩展名启动 Access)。

如果上述方法不起作用(按住 shift 键),则只需创建一个空白的新数据库,然后从您的 mdb 导入所有对象。我推荐这个过程,因为:

您不必编写代码(根据此处的其他帖子)

导入会删除所有启动设置(从而绕过任何启动代码设置)。

当您从该应用程序导入表时,您可以(应该)使用更新版本的 Access。

所以不要尝试打开该访问文件 - 启动 Access 并创建一个空白文件,然后导入表。

【讨论】:

    【解决方案2】:

    由于它只是后端的东西,您不必担心表单或报告。您可以使用 ODBC 以编程方式打开数据库,读取 tabledef,读取每个表中的字段,然后在空白数据库中创建表。比如:

    For Each tblRep In dbRep.TableDefs
    Set rec1 = dbRep.OpenRecordset("SELECT MSysObjects.Name FROM MsysObjects WHERE ([Name] = '" & tblRep.Name & "') AND ((MSysObjects.Type)=4 or (MSysObjects.Type)=6)")
    
    If rec1.EOF Then
      XF = 0
    Else
      XF = 1
    End If
    
        ' Ignore system tables and CMDB tables.
        If InStr(1, tblRep.Name, "MSys", vbTextCompare) = 0 And _
            InStr(1, tblRep.Name, "CMDB", vbTextCompare) = 0 And _
            XF = 0 Then
    
            '***** Table definition
            ' Create a table definition with the same name.
            Set tblNew = dbNew.CreateTableDef(tblRep.Name)
    
            ' Set properties.
            tblNew.ValidationRule = tblRep.ValidationRule
            tblNew.ValidationText = tblRep.ValidationText
    
            ' Loop through the collection of fields in the table.
            For Each fldRep In tblRep.Fields
    
                ' Ignore replication-related fields:
                ' Gen_XXX, s_ColLineage, s_Generation, s_GUID, s_Lineage
                If InStr(1, fldRep.Name, "s_", vbTextCompare) = 0 And _
                    InStr(1, fldRep.Name, "Gen_", vbTextCompare) = 0 Then
    
                    '***** Field definition
                    Set fldNew = tblNew.CreateField(fldRep.Name, fldRep.Type, _
                        fldRep.Size)
    
                    ' Set properties.
                    On Error Resume Next
                    fldNew.Attributes = fldRep.Attributes
                    fldNew.AllowZeroLength = fldRep.AllowZeroLength
                    fldNew.DefaultValue = fldRep.DefaultValue
                    fldNew.Required = fldRep.Required
                    fldNew.Size = fldRep.Size
    
                    ' Append the field.
                    tblNew.Fields.Append fldNew
                    'On Error GoTo Err_NewShell
                End If
            Next fldRep
    
            '***** Index definition
    
            ' Loop through the collection of indexes.
            For Each idxRep In tblRep.Indexes
    
                ' Ignore replication-related indexes:
                ' s_Generation, s_GUID
                If InStr(1, idxRep.Name, "s_", vbTextCompare) = 0 Then
    
                    ' Ignore indices set as part of Relation Objects
                    If Not idxRep.Foreign Then
    
                        ' Create an index with the same name.
                        Set idxNew = tblNew.CreateIndex(idxRep.Name)
    
                        ' Set properties.
                        idxNew.Clustered = idxRep.Clustered
                        idxNew.IgnoreNulls = idxRep.IgnoreNulls
                        idxNew.Primary = idxRep.Primary
                        idxNew.Required = idxRep.Required
                        idxNew.Unique = idxRep.Unique
    
                        ' Loop through the collection of index fields.
                        For Each fldRep In idxRep.Fields
                            ' Create an index field with the same name.
                            Set fldNew = idxNew.CreateField(fldRep.Name)
                            ' Set properties.
                            fldNew.Attributes = fldRep.Attributes
                            ' Append the index field.
                            idxNew.Fields.Append fldNew
                        Next fldRep
    
                        ' Append the index to the table.
                        tblNew.Indexes.Append idxNew
                    End If
                End If
            Next idxRep
    
            ' Append the table.
            dbNew.TableDefs.Append tblNew
        End If
    Next tblRep
    

    以类似的方式,您将重新创建所有关系、宏、查询和模块。然后,只需使用类似的代码将它们复制过来:

    ' Loop through the list of table definitions.
    For Each tblRep In dbRep.TableDefs
    Set rec1 = dbRep.OpenRecordset("SELECT MSysObjects.Name FROM MsysObjects WHERE ([Name] = '" & tblRep.Name & "') AND ((MSysObjects.Type)=4 or (MSysObjects.Type)=6)")
    
    If rec1.EOF Then
      XF = 0
    Else
      XF = 1
    End If
    
        ' Ignore system tables and CMDB tables.
        If InStr(1, tblRep.Name, "MSys", vbTextCompare) = 0 And _
            InStr(1, tblRep.Name, "CMDB", vbTextCompare) = 0 And _
            XF = 0 Then
    
            ' Open a recordset for the new table.
            Set rstNew = dbNew.OpenRecordset(tblRep.Name, dbOpenTable)
            ' Open a recordset for the old table.
            Set rstRep = dbRep.OpenRecordset(tblRep.Name, dbOpenTable)
    
            ' Continue if there are records.
            If Not rstRep.BOF Then
    
                ' Move to the first record.
                rstRep.MoveFirst
    
                ' Loop through all the old table records.
                Do Until rstRep.EOF
                    ' Add a record to the new table.
                    rstNew.AddNew
                    ' For each field in the new table, set the value
                    ' to the value in the related field of the old table.
                    For intC = 0 To rstNew.Fields.count - 1
                        rstNew.Fields(intC).Value = _
                            rstRep.Fields(rstNew.Fields(intC).Name).Value
                    Next
                    ' Update the new table.
                    rstNew.Update
                    ' Move to the next old table record.
                    rstRep.MoveNext
                Loop ' rstRep
            End If
    
            ' Close the new recordset.
            rstNew.Close
            ' Close the old recordset.
            rstRep.Close
        End If
    Next tblRep
    

    【讨论】:

      【解决方案3】:

      创建空的 Access 数据库并将表从 MDB 文件链接到新数据库。您应该能够从链接表中执行查询和报告,或者可能备份和移动数据。

      我强烈建议先备份所有数据,然后再以这种方式进行任何更改。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-26
        • 2019-10-08
        • 1970-01-01
        • 2018-09-04
        • 1970-01-01
        • 2022-01-14
        相关资源
        最近更新 更多