LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default strange error message following INSERT INTO statement

Hi there

I'm using ADO from within an Excel VBA procedure to import a fairly large
text file (1GB+) into an Access database.

Everything's running smoothly (thanks to the help from this group!), except
when I get to the final INSERT INTO statement. My code (a bit truncated) is
as follows ...

Dim cnNew As ADODB.Connection
Dim catNew As ADOX.Catalog
Dim tblNew As ADOX.Table
Dim colNew As ADOX.Column

strConnect = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\DestinationFile.mdb;"
Set cnNew = New ADODB.Connection
cnNew.Open strConnect

Set catNew = New ADOX.Catalog
Set catNew.ActiveConnection = cnNew

Set tblNew = New ADOX.Table
tblNew.Name = tblName

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\PathToTextFile\TextFile.tx t", 1)
strColHeaders = objFile.ReadLine
objFile.Close

arrColHeaders = Split(strColHeaders, "|", -1, 1)

For Each strColHeader in arrColHeaders
Set colNew = New ADOX.Column
colNew.Name = strColHeader
colNew.Type = adVarWChar
colNew.DefinedSize = 24
colNew.Attributes = adColNullable
tblNew.Columns.Append colNew.Name, colNew.Type, colNew.DefinedSize
Next

catNew.Tables.Append tblNew

cnNew.Execute "INSERT INTO " & tblName & " SELECT * FROM
[Text;Database=C:\PathToTextFile\;HDR=YES].[" & txtFileName & ".txt]"

At this point I get a run-time error '-2147217900 (80040e14)' ~ "The INSERT
INTO statement contains the following unknown field name: 'Inv# To'. Make
sure you have typed the name correctly, and try the operation again."

I don't know where the "#" character arises... For instance, when I manually
import the text file into an Access database, the field/column name (in
design view) is given as "Inv To" (words separated by a space), and the same
result is achieved if I import the text file (at least the first 2^16 rows
of the text file) into Excel.

However, if I view the text file in Windows Commander (the file is too big
to view in Notepad etc.), the field name is given as "Inv. To" (both a space
and a period), while the error message bizarrely suggests that the field
name contains a "#".

I'm about ready to fly off the handle!

Please help
Loane


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
cant insert column get error message sheppey Excel Worksheet Functions 2 May 6th 08 02:13 PM
Error message in macro to insert new row? Wuddus Excel Discussion (Misc queries) 2 September 5th 06 03:31 PM
Getting error message when I try to insert rows. jkc1 Excel Discussion (Misc queries) 1 April 13th 06 07:19 PM
Strange Error Message Michael Windmeier Excel Discussion (Misc queries) 0 December 3rd 04 08:18 AM
Strange error message Jeroen Kluytmans Excel Programming 4 May 12th 04 12:33 PM


All times are GMT +1. The time now is 05:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"