尝试将 Access 中的附件重命名为 table 中的字段

Trying to rename an attachment in Access to a field in the table

目前我有一个 table,其中 'ID' 字段是通过多个其他字段的组合自动生成的。示例:ID = '2017_FileName_Chancellor' 现在我一直在想办法让我将此附件重命名为该 ID(可能通过按表单中的按钮),而无需手动复制粘贴 ID 并重命名附件,因为这样做会很乏味数千条记录。无论如何我可以这样做吗?我对 VBA 一无所知,所以我无法篡改它。

提供我的 table 的照片可能会有所帮助 https://i.imgur.com/gaTUCtk.png

要在 Access 中更改附件名称:

Private Sub Command15_Click()
    Dim NewName As String
    Dim NewNameWithExt As String

    NewName = Me.TestID.Value

    NewNameWithExt = NewName & ".txt"

    DoCmd.RunSQL ("UPDATE TestTable SET TestAttachment.FileName = '" & 
    NewNameWithExt & "' WHERE TestID = " & NewName)

End Sub

要更改桌面上文件的名称:

Private Sub Command0_Click()
    Dim NewName As String
    Dim OldName As String
    Dim rs As Object
    Dim strSQL As String

    Set rs = CreateObject("ADODB.Recordset")

    strSQL = "SELECT TestAttachment.FileName FROM TestTable WHERE TestID = 1"

    rs.Open strSQL, CurrentProject.Connection, 1, 3

    Do Until rs.EOF
        OldName = rs.Fields(0)
        NewName = CurrentDb.TableDefs("TestTable").Fields(0).Name

        Name "C:\Users\TestUser\desktop\" & OldName As 
        "C:\Users\TestUser\desktop\" & NewName & ".TXT"

        rs.MoveNext
    Loop

    rs.Close
    Set rs = Nothing

End Sub