Solved

VB.net Access Table seems to append rather than ovewrite

Posted on 2013-12-08
2
329 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
[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 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

728 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