Results 1 to 6 of 6

Thread: Replacing/Adding entrie in Access

Threaded View

  1. #1

    Thread Starter
    Addicted Member Fonty's Avatar
    Join Date
    May 2006
    Location
    New York
    Posts
    173

    Post Replacing/Adding entrie in Access

    I'm trying to fill a table in access from a table in Excel. The code is enbeded in an Excel worksheet.
    I'm using the following code:

    Code:
    Sub Export()
    
    Dim db As Database
    Dim rs As Recordset
    Dim col, row, field_count, i As Integer
    Dim MyField, tabla As String
    
    Set db = OpenDatabase("C:\Base.mdb")
    
    table = "TABLE"
    
    Set rs = db.OpenRecordset(table, dbOpenTable)
    
    row = 2
    
    Do While Len(Range("A" & row).Formula) > 0
        With rs
           field_count = 5
            .AddNew
            For i = 1 To field_count
                MyField= Worksheets("FIELDS").Cells(i + 3, 1).Value
                col= Worksheets("FIELDS").Cells(i + 3, 3).Value
                .Fields(MyField) = Worksheets(table).Cells(row, col).Value
            Next i
            .Update
        End With
        row= row+ 1
    Loop
    
    rs.Close
    Set rs = Nothing
    db.Close
    Set db = Nothing
        
    End Sub
    The problem is that using .AddNew, I'm just adding a new entry and it won't just replace prior entries. I thought of two solutions. Either deleting the whole entries of the table and the adding the new entries, or replacing every entry one by one. How could I solve this?
    Last edited by Fonty; Apr 24th, 2007 at 07:25 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width