Hi All,
If any one can help me out. I am new in VB Macro and trying to write the macro for update access table from Excel. Using below codes but getting error on ".Find".
Macro Reference seeting - Microsoft DAO 3.6 Object Libraey
If you r having any other code for the same tack pls guide and suggest....
Thanks in advance.....
Code:-
Sub up()
Dim db As Database
Dim rs As Recordset
Dim r As Long
Dim myDB As String
Dim wks As Worksheet
Sheets("Job_Details").Select
Range("A1").Select
myDB = "C:\New_Project\RR.mdb"
Set db = OpenDatabase(myDB)
' open the database
Set rs = db.OpenRecordset("Work", 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 B
With rs
'This would search for your primary key field, which I've assumed to be Ref.
.Find "Prgm_Name1 = " & Range("A" & r).Value
If .EOF Then
'Record not found, you could include the Addnew line here.
Else
'Record found...
End If
.AddNew ' create a new record
' add values to each field in the record
.Fields("Status") = Range("J" & r).Value
' add more fields if necessary...
.Update ' stores the new record
End With
r = r + 1 ' next row
Loop
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
MsgBox "Appended " & r - 2 & " Records to your database", vbOKOnly, "Confirmation"
End Sub
Bookmarks