Solved

VB.net Access Table seems to append rather than ovewrite

Posted on 2013-12-08
2
328 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 a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

726 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