?
Solved

VB.net Access Table seems to append rather than ovewrite

Posted on 2013-12-08
2
Medium Priority
?
330 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
Bill Ross earned 2000 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:Murray Brown
ID: 39704160
Thanks very much
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Suggested Courses

770 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