创建并在前台使用VBA在后端连接一个新表

问题描述 投票:0回答:1

林在我访问前端在我访问后端来创建一个新表使用VBA,那么我的表链接到我的前端。表和索引的创建成功,但我不断收到同样的错误说,后端是由其他用户使用,当我尝试在前端创建一个链接表。我怎样才能解决这个问题。我已经在这个项目上,过去做过几次,但突然它不希望再工作。

我曾尝试在后端创建表,然后再添加值表中,然后关闭到后端数据库的连接,并重新连接到它,然后向链路传送到前端。没有去,同样的错误一遍又一遍。我访问这两个文件的唯一的人。后端甚至不显示锁定的文件,但它仍然说,我不能访问它。

Private Sub Command1_Click()
On Err GoTo errExit
Dim dbs As DAO.Database
Dim DB_PATH As String
Dim strConn As String

    DB_PATH = DLookup("BackendDirectory", "Link_Save")
    strConn = "MS Access;PWD=" & BE_PASSWORD & ";DATABASE=" & DB_PATH
    Set dbs = OpenDatabase(DB_PATH, True, False, strConn)

'Create table tbl_Client_Type

        dbs.Execute "CREATE TABLE tbl_Client_Type (Client_Type_ID COUNTER CONSTRAINT PrimaryKey PRIMARY KEY, " & _
                                        "Client_Type TEXT(100) NOT NULL);"

        dbs.Execute "CREATE INDEX Client_Type_ID ON tbl_Client_Type (Client_Type_ID ASC);"

        DoEvents: 
        dbs.Execute "INSERT INTO tbl_Client_Type (Client_Type) VALUES ('Motor')"
        dbs.Execute "INSERT INTO tbl_Client_Type (Client_Type) VALUES ('Sail')"
        dbs.Execute "INSERT INTO tbl_Client_Type (Client_Type) VALUES ('Other')"
        DoEvents:

        'dbs.Close
        'Set dbs = Nothing
        'Set dbs = DBEngine.OpenDatabase(DB_PATH, True, False, strConn)
        DoEvents:

        DoCmd.TransferDatabase acLink, "Microsoft Access", DB_PATH, acTable, "tbl_Client_Type", "tbl_Client_Type"

        DoEvents:
        RefreshLinkedTable "tbl_Client_Type"
        Application.RefreshDatabaseWindow

    dbs.Close
    Set dbs = Nothing

errExit:
   Debug.Print Err.Number
    Debug.Print Err.Description

End Sub

运行时错误3045“无法使用‘数据库’,文件已在使用

该文件不是在使用和不laccdb锁定文件

vba ms-access ms-access-2016
1个回答
0
投票

尝试打开共享数据库:

Set dbs = OpenDatabase(DB_PATH, False, False, strConn)
© www.soinside.com 2019 - 2024. All rights reserved.