Solved

Failure of INSERT INTO...

Posted on 2002-06-08
3
208 Views
Last Modified: 2012-06-27
I wrote a simple script using the Jet 4.0 Provider to assist in removing duplicates from a standard ASCII file, while keepng the original line number intact ( hence I could not use a DISTINCT clause ). The SQL statements follow:

; import the text file
'SELECT * INTO [line] FROM [input.txt] IN "" [TEXT;DATABASE=c:\temp]'

;add a line counter
'ALTER TABLE line ADD linecount COUNTER'

;create a temp table with a constraint
"CREATE TABLE temp (line TEXT (50),linecount COUNTER );"
'CREATE UNIQUE INDEX temp ON temp (line)'

'INSERT INTO temp (line,linecount) SELECT * FROM line;'

"SELECT line INTO [Text;DATABASE=c:\temp].[output.txt] FROM temp ORDER BY linecount"


I get no errors, but both the output file and temp table are blank.

If I open Access, create a query and type in the INSERT statment above, it work fine, but Access forces you to confirm 2 warning screens saying it cannot apend all records.

I was wondering if this could be part of the problem and perhaps I need to add something to the script to turn the warnings off.

stan
0
Comment
Question by:stanl
3 Comments
 
LVL 54

Expert Comment

by:nico5038
ID: 7064561
Hi stanl,

Why are you using a script?
You can define a linked table in access to your textfile and issue all needed queries on that linked table.

Removing duplicates could be done by a GroupBy query to select the first line of each unique value and followed by a delete of the non-matching.

Nic;o)
0
 
LVL 9

Accepted Solution

by:
ornicar earned 200 total points
ID: 7064991
If you want to turn the messages off, just use:

DoCmd.SetWarnings False

And to turn them on again:

DoCmd.SetWarnings True

The duplicates will not be added with no message. If this is ok for you, that's fine. I feel it would be better to import into an intermediate table allowing duplicates, then run a check-duplicates query to show these records. Very often it's better to check why there are duplicates and what there are. Just a guess.

0
 

Author Comment

by:stanl
ID: 7065160
As it turned out, if I changed my original OLE Object from the Jet OLEDB Provider to Access.Application the script worked fine.  Since the DoCmd is not part of the Provider Object, that got me thinking about making that change ( but there was never a need to even touch the SetWarnings property.

I agree about holding the duplicates, but the text files are created by 'cut-and-paste' which is subject to slight error.



0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now