3

I have 2 Access database files. Database no. 1 is in my computer and database no. 2 is in the network shared folder.

I create a form in database 1 (in my computer) that inserts form data to table "Tbl_Requests" with following VBA code:

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

Now I want save the same data form to another table in database 2 that is in the network. How can I do this?

Picture Of Question

2 Answers 2

3

Simply switch out the CurrentDb object and point to networked database file:

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
Sign up to request clarification or add additional context in comments.

Comments

1

Link TableB from DB2 into DB1.

The linked table can be used (for most use cases) like a local table, your code works without changes, except perhaps the table name.

1 Comment

can i do it with vba code and Such as the above codes insert record to table B?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.