Insert flat file to access DB error on one PC
For some reason the below code works on all PCs but there is one company that it will not work for. They have tried on several PCs and everytime they get an error saying that the query fields are not the same. This usually makes sense and I just replace the database and it works. For some reason the text file matches the database table and it still will not work. I have tested the program on my pc using there databases and it works fine with both examples below. I am thinking that it is something to do with the text driver so I tried the second example below and with that example 2 only the first column of data is insterted into the table. I have used the mdac compenent checker and ther are no mismatch files. Any other suggestions as to what compenent to check or a reason why it will work on hundreds of other customers PCs but not at one location?
example 1
strCn = "Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
"DBQ=" & App.Path & ";" & _
"DefaultDir=" & App.Path & ";" & _
"Uid=Admin;Pwd=;"
strSql = "INSERT INTO [" & FileName & "] IN '" & dbLocation & "'"
strSql = strSql & " SELECT * FROM " & TextFile
frmftp.adoCn.Execute strSql, a
example 2
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbLocation
Dim counter As String
counter = InStrRev(TextFile, "\")
textfile1 = Left(TextFile, InStrRev(TextFile, "\"))
textfile2 = Right(TextFile, Len(TextFile) - counter)
textfile1 = "[Text;Database=" & textfile1 & ";HDcn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbLocationR=YES].[" & textfile2 & "]"
cn.Execute "Insert INTO " & FileName & " select * FROM " & textfile1
[1764 byte] By [
DrunkMunk] at [2007-11-11 8:49:41]

# 1 Re: Insert flat file to access DB error on one PC
The syntax here looks a little odd to me (specifically example 2). Here is an example that I often use:
Dim cnn As New ADODB.Connection
Dim strSQL As String
cnn.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Documents and Settings\...\My Documents\Database\db2003.mdb;" & _
"Jet OLEDB:Engine Type=4;"
strSQL = "INSERT INTO [tblNames] SELECT * FROM [Text;DATABASE=C:\Documents and Settings\...\My Documents\Database\TextFiles;].[Names.txt]"
cnn.Execute strSQL
cnn.Close
This assumes the column names are the same in the Access table and text file. If not then they would need to be specified in the SQL statement.