Hi Poppe,
Here is a way to do it using DAO. You need to set a reference to 'Microsoft
DAO 3.6 Object Library' in the VBE Tools -> References menu before running
this code.
AFAIK this works on all versions of Excel from 95 on.
Hopefully this will get you started.
Ed Ferrero
www.edferrero.com
==============================================
Option Explicit
' change a database record using DAO
Sub CopyChangedRecords()
'Dim DataSource As Variant
Dim name_of_database As String
Dim WS1 As Workspace
Dim Db1 As Database
Dim Rs1 As Recordset
Dim findstring As String
' this sample makes a change to an Access database table
' database: SciFi.mdb
' Table: Publisher
' Fields: Publisher text - primary key
' Country text
name_of_database = "D:\Documents\Developent\Ed\EIS\SciFi.mdb"
' use DAO to write to the database
With DBEngine
Set WS1 = .CreateWorkspace(Name:="Work_S1", _
UserName:="Admin", _
Password:="")
.Workspaces.Append WS1
End With
Set Db1 = WS1.OpenDatabase(Name:=name_of_database, ReadOnly:=False)
Set Rs1 = Db1.OpenRecordset(Name:="Publisher", Type:=dbOpenDynaset)
' update records
' find record by searching primary key
findstring = "[Publisher]='Avon'"
With Rs1
.FindFirst findstring
.Edit
.Fields("Country").Value = "UK"
.Update
End With
' clean up
Db1.Close
Set Rs1 = Nothing
Set Db1 = Nothing
Set WS1 = Nothing
End Sub