View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
MikeS[_2_] MikeS[_2_] is offline
external usenet poster
 
Posts: 12
Default Overwrite a record instead of add

I have the following code that adds a record to an Access database:

Sub ADOFromExcelToAccess()
Dim cn As ADODB.Connection, rs As ADODB.Recordset
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=S:\MalLab\MAL_DB.mdb;"
Set rs = New ADODB.Recordset
rs.Open "CurrentPMT", cn, adOpenKeyset, adLockOptimistic, adCmdTable
With rs
.AddNew
.Fields("CurrentPMTScore") = Sheet1.Range("F1").Value
.Update
End With
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub

Can someone tell me how to overwrite the existing record instead of adding a
new one.

Thanks in advance,

MikeS