I currently have a process where I import around 10 .txt files into a database each week replacing exisitng ones. Each has it's own specification and 2 have primary keys. I decided to automatically do this using a macro. Code I am using is below...
DoCmd.DeleteObject acTable, "Agency"
DoCmd.TransferText acImportDelim, "Agency Import Specification", _
"Agency", "U:\AS\MIdata\Database\agency.txt"
DoCmd.OpenQuery ("Agency_Prim_Key")
The SQL for the above is below
ALTER TABLE Agency
ADD PRIMARY KEY (uan);
Problems Encountered...
- When doing this process manually I just import and it over-writes the existing table but when I use the VBA method it seems to append for some reason. I have therefore added code to delete the original.
- The second and main problem is that after importing it comes up with creating and changing indexes which not only takes time but is not something I do not want to happen and doesn't happen when doing manually presumably because I am choosing a primary key (or not in other circumstances) in the import wizard.
Does anyone know a way to import without Access adding its own Indexes (I am not sure the knock on effect of indexes on a table if I am ignorantly honest) but I know it adds time to the macro. Similarlly does anyone know why it appends rather than replacing? As always your help is appreciated.
Thanks
Bookmarks