D
damarsh
I need to update an existing database entry with a new values. My current
code is shown below. This code adds a new entry, but a couple days after I
have added this new entry, I want to update this new entry with new data.
This new entry would be unique by the Date and Node Entry together (Range A
and B). I found some code using the '.Find' function, but returns error
'Method or Data Member Not Found'. Any help on this matter would be much
appreciated.
Sub Dbase()
Dim db As DAO.Database, rs As DAO.Recordset, r As Long
'Starting Row in Worksheet
r = 2
Set db = OpenDatabase("T:\Data\XXX.mdb")
Set rs = db.OpenRecordset("MISO Real Time LMP", dbOpenTable)
'Repeat Until 0 Value Reached in Column D
Do Until Range("D" & r).Value = Change
With rs
On Error Resume Next
'Create New Record
.AddNew
.Fields("Date") = Range("A" & r).Value
.Fields("Node") = Range("B" & r).Value
.Fields("Type") = Range("C" & r).Value
.Fields("HE 1") = Range("E" & r).Value
.Fields("HE 2") = Range("F" & r).Value
.Fields("HE 3") = Range("G" & r).Value
.Fields("HE 4") = Range("H" & r).Value
.Fields("HE 5") = Range("I" & r).Value
.Fields("HE 6") = Range("J" & r).Value
.Update
End With
r = r + 1
Loop
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
End Sub
code is shown below. This code adds a new entry, but a couple days after I
have added this new entry, I want to update this new entry with new data.
This new entry would be unique by the Date and Node Entry together (Range A
and B). I found some code using the '.Find' function, but returns error
'Method or Data Member Not Found'. Any help on this matter would be much
appreciated.
Sub Dbase()
Dim db As DAO.Database, rs As DAO.Recordset, r As Long
'Starting Row in Worksheet
r = 2
Set db = OpenDatabase("T:\Data\XXX.mdb")
Set rs = db.OpenRecordset("MISO Real Time LMP", dbOpenTable)
'Repeat Until 0 Value Reached in Column D
Do Until Range("D" & r).Value = Change
With rs
On Error Resume Next
'Create New Record
.AddNew
.Fields("Date") = Range("A" & r).Value
.Fields("Node") = Range("B" & r).Value
.Fields("Type") = Range("C" & r).Value
.Fields("HE 1") = Range("E" & r).Value
.Fields("HE 2") = Range("F" & r).Value
.Fields("HE 3") = Range("G" & r).Value
.Fields("HE 4") = Range("H" & r).Value
.Fields("HE 5") = Range("I" & r).Value
.Fields("HE 6") = Range("J" & r).Value
.Update
End With
r = r + 1
Loop
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
End Sub