Import CSV file

J

jesseb

Here is my code attached to a button:
DoCmd.TransferText acImportDelim, , "Table1", "C:\testing.csv", True, ""

It works but I get a prompt about: unable to append all the data to the table
The contents of the fields in 0 record(s) were deleted, and 1 record(s) ...
etc.

I would like to surpress the message so the user does not need to deal with
it.
Anyone with suggestions?

Thanks, Jesseb
 
J

Jack Leach

You can supress messages by using DoCmd.SetWarnings False. Beware though...
always make sure you turn it back on in the exit procedure and/or error
handler so you don't accidentally leave it off.

But, is there some reason all of the data is not being appended? Are you
comfortable with the results of the transfer? You will have no notification
of anything going wrong with SetWarnings off... you may want to include some
code to somehow verify the transfer.

Private Sub DoSomething()
On Error Goto Err_Handler

DoCmd.SetWarnings False
DoCmd.TransferText acImportDelim, , "Table1", "C:\testing.csv", True, ""
DoCmd.SetWarnings True

Exit_Proc:
DoCmd.SetWarnings True
Exit Sub
Err_Handler:
DoCmd.SetWarnings True
MsgBox Err.Number & " " & Err.Description
Resume Exit_Proc
End Sub


hth
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
J

jesseb

Thanks this will work great!
You are correct and I think I have found my problem. When I removed the
Primary Key the error goes away. So by changing the table I should be able to
import and leave the warning active.
Thanks again, Jesseb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top