How can I update an Access Table from Excel data?

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
788
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have an 8 column table in access named DATA1 which I pull into Excel based on date.

Example (SELECT * from DATA1 where EDAT = " '20181108'")

Does anyone know if it's possible with VBA to edit the pulled data and update the access table with new values ?


Appreciate any help
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Why not just create your table in Excel and link it to Access. When you do it this way, any changes you make to the table in Excel is automatically synced to Access.
 
Upvote 0
Why not just create your table in Excel and link it to Access. When you do it this way, any changes you make to the table in Excel is automatically synced to Access.

Thanks for the reply
I looked into this option but it doesn't allow you to add records directly into the database which I need also.
 
Upvote 0
I just test this and I can add records to the Excel workbook and they are immediately updated in the Access Data Base. So, I believe that either you and I are not on the same page or your sources are mistaken. I urge you to test it out yourself with a test workbook and test DB to satisfy yourself. Then try it in your production Database.
 
Upvote 0
Yes that works, though I need to add records from a non-linked workbook
 
Upvote 0
Import the non-linked workbook and as long as it is in the same format as the linked table, you can append the records. Alternatively, you could cut and paste the records from the non-linked to the linked and they will update.
 
Upvote 0
In my SQL sheet, I first pull data from access based on date then modify the records. Unsure if I can do the same with a linked table

I think this is close to what I need but don't quite understand it yet

Code:
Public Const Conn As String = "Data Source=Path\Database.accdb;"
Private Sub Export_Click()
Dim rs As New ADODB.Recordset
Dim cn As New ADODB.Connection
Dim ssql As String, tbl As String
Dim ID As Integer

tbl = "Table"
ID = IDLoan
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & Conn

If IDLoan = "" Then     'IF NEW
    rs.Open tbl, cn, adOpenKeyset, adLockOptimistic, adCmdTableDirect
    rs.AddNew
Else                    'If Existing
    ssql = "SELECT * FROM " & tbl & " WHERE " & tbl & ".ID=" & ID
    rs.Open source:=ssql, ActiveConnection:=cn, CursorType:=adOpenKeyset, _
        LockType:=adLockOptimistic, Options:=adCmdTableDirect
End If
With rs
    .Fields("FieldName1") = [A1]
    .Fields("FieldName2") = [C3]
    .Fields("FieldName3") = [C4]
    'repeat for all required fields
    .Update
    .Close
End With
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub

From
https://www.mrexcel.com/forum/excel-questions/911978-updating-record-access-excel-vba.html

I only need to modify the 8th column
Column A (ID) is the primary key
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top