Solved

VB.net Access Table seems to append rather than ovewrite

Posted on 2013-12-08
2
319 Views
Last Modified: 2013-12-08
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
0
Comment
Question by:murbro
2 Comments
 
LVL 14

Accepted Solution

by:
Bill Ross earned 500 total points
ID: 39704141
Hi,

Put this statement in just before the if statement:

appAccess.docmd.DeleteObject acTable,oTableName

Regards,

Bill
0
 

Author Closing Comment

by:murbro
ID: 39704160
Thanks very much
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now