刷新access中的链接表

发布于 2024-10-03 16:22:28 字数 123 浏览 3 评论 0原文

嘿。 我的主访问数据库位于一台脱离网络的独立 PC 上,并且我有一个访问数据库,其网络上的链接表链接回独立 PC。我通过创建到独立 PC 的网络共享并通过路径链接它们来链接这些表。我可以将其设置为在打开数据库时自动更新链接表吗? 本

Hey.
I have the main access database located on a stand alone PC off the network and i have a access database with linked tables on the network linked back to the stand alone PC. I have linked the tables by creating a network share to the stand alone PC and linking them though a path. Can i set it up so that when the database is opened it automatically updates the linked tables.
Ben

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

揽月 2024-10-10 16:22:28

你可以。我经常发现使用在启动时运行的小型检查表单(通过启动选项设置)并检查各种内容(包括链接表)很方便。为此,我还在本地机器上保存了一个链接表的表,虽然可以通过迭代TableDefs集合来获取链接表的列表,但我认为保留一个列表稍微安全一些。

检查表单可以检查所有链接,如果链接损坏或丢失,请询问用户新位置或使用固定位置。如果没有发现问题,表单可以自行关闭并打开菜单或其他表单。

在链接到链接表的情况下,可以从以下位置获取要使用的连接:

 CurrentDB.TableDefs("TableName").Connection

以下是更多注意事项:

Sub RelinkTables(Optional strConnect As String = "")
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL
Dim tdf As DAO.TableDef

On Error GoTo TrapError

    Set db = CurrentDb

    If strConnect = "" Then
        ''Where Me.txtNewDataDirectory is a control on the check form
        strConnect = "MS Access;PWD=databasepassword;DATABASE=" & Me.txtNewDataDirectory
    End If

    ''Table of tables to be linked with two fields TableName, TableType
    Set rs = CurrentDb.OpenRecordset("Select TableName From sysTables " _
           & "WHERE TableType = 'LINK'")

    Do While Not RS.EOF
        ''Check if the table is missing
        If IsNull(DLookup("[Name]", "MSysObjects", "[Name]='" & rs!TableName & "'")) Then
            Set tdf = db.CreateTableDef(RS!TableName, dbAttachSavePWD, _
                rs!TableName, strConnect)
            ''If the table is missing, append it
            db.TableDefs.Append tdf
        Else
            ''If it exists, update the connection
            db.TableDefs(rs!TableName).Connect = strConnect
        End If
        db.TableDefs(rs!TableName).RefreshLink
        RS.MoveNext
    Loop

    Set db = Nothing
    RS.Close
    Set RS = Nothing


Exit_Sub:
    Exit Sub

TrapError:
    HandleErr Err.Number, Err.Description, "Relink Tables"

End Sub

You can. I often find it convenient to use a small check form that runs on start-up (set through start-up options) and checks a variety of things, including linked tables. To this end, I also hold a table of linked tables on the local machine, although a list of linked tables can be obtained by iterating through the TableDefs collection, I think it is slightly safer to keep a list.

The check form can check all links and if a link is broken or missing, either ask the user for a new location or use a fixed location. If no problems are found, the form can close itself and open a menu or other form.

In the case of linking to a linked table, it is possible to get the connection to use from:

 CurrentDB.TableDefs("TableName").Connection

Here are some more notes:

Sub RelinkTables(Optional strConnect As String = "")
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL
Dim tdf As DAO.TableDef

On Error GoTo TrapError

    Set db = CurrentDb

    If strConnect = "" Then
        ''Where Me.txtNewDataDirectory is a control on the check form
        strConnect = "MS Access;PWD=databasepassword;DATABASE=" & Me.txtNewDataDirectory
    End If

    ''Table of tables to be linked with two fields TableName, TableType
    Set rs = CurrentDb.OpenRecordset("Select TableName From sysTables " _
           & "WHERE TableType = 'LINK'")

    Do While Not RS.EOF
        ''Check if the table is missing
        If IsNull(DLookup("[Name]", "MSysObjects", "[Name]='" & rs!TableName & "'")) Then
            Set tdf = db.CreateTableDef(RS!TableName, dbAttachSavePWD, _
                rs!TableName, strConnect)
            ''If the table is missing, append it
            db.TableDefs.Append tdf
        Else
            ''If it exists, update the connection
            db.TableDefs(rs!TableName).Connect = strConnect
        End If
        db.TableDefs(rs!TableName).RefreshLink
        RS.MoveNext
    Loop

    Set db = Nothing
    RS.Close
    Set RS = Nothing


Exit_Sub:
    Exit Sub

TrapError:
    HandleErr Err.Number, Err.Description, "Relink Tables"

End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文