Murray Brown
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.oR IGHT.lblCo nnectionSt ring.Text, "=")
Dim Access_File_Path As String = Mid(arrSplit(2), 1, Len(arrSplit(2)) - 1)
Dim appAccess As New Microsoft.Office.Interop.A ccess.Appl ication
appAccess.OpenCurrentDatab ase(Access _File_Path )
appAccess.Visible = True
If oSpecificationName = "" Then
appAccess.DoCmd.TransferTe xt(Transfe rType:=Mic rosoft.Off ice.Intero p.Access.A cTextTrans ferType.ac ImportDeli m, TableName:=oTableName, _
FileName:=oTextFilePath, HasFieldNames:=True)
Else
appAccess.DoCmd.TransferTe xt(Transfe rType:=Mic rosoft.Off ice.Intero p.Access.A cTextTrans ferType.ac ImportDeli m, SpecificationName:=oSpecif icationNam e, TableName:=oTableName, _
FileName:=oTextFilePath, HasFieldNames:=True)
End If
appAccess.CloseCurrentData base()
appAccess = Nothing
Catch ex As Exception
MsgBox(ex.Message & " poph11")
End Try
End Sub
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
Try
Dim arrSplit As Object = Split(Globals.ThisAddIn.oR
Dim Access_File_Path As String = Mid(arrSplit(2), 1, Len(arrSplit(2)) - 1)
Dim appAccess As New Microsoft.Office.Interop.A
appAccess.OpenCurrentDatab
appAccess.Visible = True
If oSpecificationName = "" Then
appAccess.DoCmd.TransferTe
FileName:=oTextFilePath, HasFieldNames:=True)
Else
appAccess.DoCmd.TransferTe
FileName:=oTextFilePath, HasFieldNames:=True)
End If
appAccess.CloseCurrentData
appAccess = Nothing
Catch ex As Exception
MsgBox(ex.Message & " poph11")
End Try
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER