Function or macro to load comma delimited file

B

Brian

Is it possible to create a function or macro that would
automatically load data into a file?

The file I need to import is a text csv (comma delimited
file with a header row) file into an existing Access
table.
I get these files weekly and would like to automatically
load them.

I would like to have them load without any intervention
form the user. Although, something should be sent back
notifying the user if there were problems with the load.

Can you please instruct on how to do this either by
creating a macro, or by code.

Thanks
 
K

Kevin3NF

You can create a macro with a TransferText action to move the file. I'm
fairly sure there is a way to automate it, but it's not coming to me just
now....

--
Kevin Hill
President
3NF Consulting

www.3nf-inc.com/Newsgroups
 
P

Peter Hill

Yes, you can do this.
Firstly, you should create an import spec.
Do this by importing the file manually
- File -> Get External Data etc.
Before you click OK to import the file (the very final
step), click on the 'Advanced' button.
Check that you have set up the import correctly (you'll
see what I mean when you get here), then save the spec.
We'll pretend you called it "TEST_SPEC"
You only have to do this once, unless the file format
changes.

Now, you can import the file using DoCmd.TransferText
eg.
Say you want to import the file C:\Example.csv into the
table Test_Table. The Example.csv has NO header line.

On Error goto Error_Handler

DoCmd.TransferText
acImportDelim, "TEST_SPEC", "Test_Table", "C:\Example.csv",
False

Exit Sub
Error_Handler:
Msgbox "Error importing"

Or something along those lines!

That's my take!
 

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