gpt4 book ai didi

database - 将 MS Access 表单数据插入另一个 Access 表

转载 作者:搜寻专家 更新时间:2023-10-30 19:42:45 25 4
gpt4 key购买 nike

我有 2 个 Access 数据库文件。数据库编号1 在我的电脑和数据库中没有。 2 在网络共享文件夹中。

我在数据库 1(在我的计算机中)中创建了一个表单,该表单使用以下 VBA 代码将表单数据插入表“Tbl_Requests”:

Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("Tbl_Requests")
With rst
.AddNew
.Fields("IDLeave") = Me.Text_IDLeave.Value
.Fields("PersonalCode") = Me.Text_CP.Value
.Fields("FullName") = Me.Text_FullName.Value
.Fields("RequestDate") = Me.Text_RequestDate.Value
.Fields("Section") = Me.Text_Section.Value
.Fields("SuperName") = Me.Text_SuperName.Value
.Fields("LeaveRemained") = Me.Text_LeaveRemained.Value
.Fields("Des") = Me.Text_Des.Value
.Fields("LeaveDate") = Me.Combo_LeaveDate.Value
.Fields("Email") = Me.Text_Email.Value
.Update
End With

现在我想将相同的数据形式保存到网络中数据库 2 中的另一个表中。我该怎么做?

Picture Of Question

最佳答案

只需切换出 CurrentDb 对象并指向网络数据库文件:

Dim db As Database
Dim rst As Recordset

Set db = OpenDatabase("C:\Path\To\Database.accdb")
Set rst = db.OpenRecordset("Tbl_Requests")

With rst
.AddNew
.Fields("IDLeave") = Me.Text_IDLeave.Value
.Fields("PersonalCode") = Me.Text_CP.Value
.Fields("FullName") = Me.Text_FullName.Value
.Fields("RequestDate") = Me.Text_RequestDate.Value
.Fields("Section") = Me.Text_Section.Value
.Fields("SuperName") = Me.Text_SuperName.Value
.Fields("LeaveRemained") = Me.Text_LeaveRemained.Value
.Fields("Des") = Me.Text_Des.Value
.Fields("LeaveDate") = Me.Combo_LeaveDate.Value
.Fields("Email") = Me.Text_Email.Value
.Update
End With

rst.Close
db.Close

Set rst = Nothing
Set db = Nothing

关于database - 将 MS Access 表单数据插入另一个 Access 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40632092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com