vba needed to edit access table

greegan

Well-known Member
Joined
Nov 18, 2009
Messages
643
Office Version
  1. 365
Platform
  1. Windows
Hello,
I'm using Excel 2007, although others in the office may use 2010, and Access 2010 which I'm the only one that has it installed.

I have the following code (website included) which adds the data to my access table nicely.
HTML:
http://www.exceltip.com/st/Import_data_from_Access_to_Excel_(ADO)_using_VBA_in_Microsoft_Excel/427.html
What I need to do is have vba edit any updates I make to my entry and well as read the table when entering the ID (or primary key)
Code:
Sub DAOFromExcelToAccess()
' exports data from the active worksheet to a table in an Access database
' this procedure must be edited before use
Dim db As Database, rs As Recordset, r As Long
    Set db = OpenDatabase("I:\Call-Centres\Access Test\transfers.mdb")
    ' open the database
    Set rs = db.OpenRecordset("tblTransfer", dbOpenTable)
    ' get all records in a table
    r = 2 ' the start row in the worksheet
    Do While Len(Range("A" & r).Formula) > 0
    ' repeat until first empty cell in column A
        With rs
            .AddNew ' create a new record
            ' add values to each field in the record
            .Fields("ID") = Range("A" & r).Value
            .Fields("Style") = Range("B" & r).Value
            .Fields("FromStore") = Range("C" & r).Value
            .Fields("ToStore") = Range("D" & r).Value
            .Fields("Qty") = Range("E" & r).Value
            .Fields("tDate") = Range("F" & r).Value
            .Fields("Sent") = Range("G" & r).Value
            .Fields("Receive") = Range("H" & r).Value
            ' add more fields if necessary...
            .Edit ' update existing record
            .Update ' stores the new record
        End With
        r = r + 1 ' next row
    Loop
    rs.Close
    Set rs = Nothing
    db.Close
    Set db = Nothing
End Sub

Thank you for any help available.


-- g
 
Last edited:

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Sorry, i didn't think of asking this in the access forum of mrexcel. if the PTB think this question is better suited for that forum, please bump it.
Thank you

-- g
 
Upvote 0

Forum statistics

Threads
1,216,426
Messages
6,130,547
Members
449,584
Latest member
kennysmith1

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