Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VB.net Access Table seems to append rather than ovewrite

Hi

I am using the following procedure to import a text file into Access.
When I run it more than once it seems to append the new data to the existing table.
How would I change the code to rather overwrite that table?

   Sub Import_CSV_to_Access_table(ByVal oTextFilePath As String, ByVal oTableName As String, ByVal oSpecificationName As String)
        Try

          Dim arrSplit As Object = Split(Globals.ThisAddIn.oRIGHT.lblConnectionString.Text, "=")
            Dim Access_File_Path As String = Mid(arrSplit(2), 1, Len(arrSplit(2)) - 1)

            Dim appAccess As New Microsoft.Office.Interop.Access.Application

            appAccess.OpenCurrentDatabase(Access_File_Path)
            appAccess.Visible = True

            If oSpecificationName = "" Then
                appAccess.DoCmd.TransferText(TransferType:=Microsoft.Office.Interop.Access.AcTextTransferType.acImportDelim, TableName:=oTableName, _
               FileName:=oTextFilePath, HasFieldNames:=True)
            Else
                appAccess.DoCmd.TransferText(TransferType:=Microsoft.Office.Interop.Access.AcTextTransferType.acImportDelim, SpecificationName:=oSpecificationName, TableName:=oTableName, _
                FileName:=oTextFilePath, HasFieldNames:=True)
            End If

            appAccess.CloseCurrentDatabase()
            appAccess = Nothing

     Catch ex As Exception
            MsgBox(ex.Message & " poph11")
        End Try
    End Sub
ASKER CERTIFIED SOLUTION
Avatar of Bill Ross
Bill Ross
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown

ASKER

Thanks very much