Good Afternoon
I am trying to update a record in my daabase from Excel.
I am new at attempting to update Access from Excel and am having an error "Method 'Range' of object' _Global' failed"
at the ****** point below. I am unsure if I am using the correct request ie find
I am trying to find the reference in cell ref "NoToCheck" in column "Ref No" in my database. As I have copied the code from the internet I am unsure of the reference of "Primary Key in the code, but the primary key is in the "Ref No".
I hope this is understandable.
Thanks in advance
I am trying to update a record in my daabase from Excel.
I am new at attempting to update Access from Excel and am having an error "Method 'Range' of object' _Global' failed"
at the ****** point below. I am unsure if I am using the correct request ie find
I am trying to find the reference in cell ref "NoToCheck" in column "Ref No" in my database. As I have copied the code from the internet I am unsure of the reference of "Primary Key in the code, but the primary key is in the "Ref No".
I hope this is understandable.
Thanks in advance
Rich (BB code):
Sub AmendAccessRecord()
Dim cnt As ADODB.Connection
Dim rst As ADODB.Recordset
Dim stDB As String
Dim stCon, NoToCheck As String
NoToCheck = Worksheets("Today").Range("F13").Value
Set cnt = New ADODB.Connection
Set rst = New ADODB.Recordset
'Pathway and name of the database
stDB = "mydestination.accdb; Jet OLEDB:Database;"
'Create the connectionstring.
stCon = "Provider=Microsoft.Ace.OLEDB.12.0; Persist Security Info = False;" & _
"Data Source=" & stDB & ";"
cnt.Open stCon
'Find and Update the record in Access
With rst
.Index = "PrimaryKey"
.CursorLocation = adUseServer
.Open "ProcessesRaised", cnt, 1, 3, adCmdTableDirect
.Seek Range("NoToCheck").Value '*********
If Not rst.EOF Then
.Fields("Due Date") = Sheets("today").Range("D16").Value
.Fields("Status") = Sheets("Today").Range("M16").Value
.Fields("Worked By") = Sheets("Advocate Data").Range("K5").Value
.Fields("Description") = Sheets("Today").Range("I16").Value
.Update
Else
MsgBox "Update Failed"
End If
End With
rst.Close
cnt.Close
Set cnt = Nothing
Set rst = Nothing
End Sub