Insert flat file to access database (not working in one location)

I am working with a program that takes flat files from an as400 and then vb takes the files and inserts them into an access database to be used. For some reason at one location the code will not work. Example 1 only copies the first col of data to the table and example 2 gives an error saying the table fields do not match the header ones in the flat file. I have verified that the database is correct and that it works on other pcs so it is not a data issue. I have also looked at mdac and there are no mismatched files. I have installed the latest jet driver pack. Now I am out of ideas on why this is happening at the one location any suggestions please help. Hopefully someone has seen this before...

Example 1

Dim cn As New ADODB.Connection

'Open a connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbLocation

strSql1 = "DELETE FROM [" & FileName & "] IN '" & dbLocation & "'"
cn.Execute strSql1
Dim counter As String
counter = InStrRev(TextFile, "\")
textfile1 = Left(TextFile, InStrRev(TextFile, "\"))
textfile2 = Right(TextFile, Len(TextFile) - counter)
textfile1 = "[Text;Database=" & textfile1 & ";HDR=YES].[" & textfile2 & "]"
cn.Execute "Insert INTO " & FileName & " select * FROM " & textfile1


Example 2

strCn = "Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
"DBQ=" & App.Path & ";" & _
"DefaultDir=" & App.Path & ";" & _
"Uid=Admin;Pwd=;"

Set frmftp.adoCn = New ADODB.Connection
frmftp.adoCn.Open strCn
Dim a
stillexecuting = True

strSql = "DELETE FROM [" & FileName & "] IN '" & dbLocation & "'"
frmftp.adoCn.Execute strSql
Do While stillexecuting
Loop

'Append data to Access table.
stillexecuting = True
strSql = "INSERT INTO [" & FileName & "] IN '" & dbLocation & "'"
strSql = strSql & " SELECT * FROM " & TextFile
frmftp.adoCn.Execute strSql, a



Answer this question

Insert flat file to access database (not working in one location)

  • Ojemzy

    We're sorry but these fora are for Dot.Net software. If you have a VB6 question, please make use of the Visual Basic 6.0 Resource Center to find a solution to your problem.

    OTOP



  • Insert flat file to access database (not working in one location)