Script to Import Table from External MS Access MDE file

G

ghadley_00

Hi,

Does anyone know of a way I can write a script that imports a table
from a particular .mde file? I don't seen any obvious way to do it as a
macro. Any suggestions if it can be done as a macro or as a written
module?

My ultimate goal is to have script that clears info out of 1 table in
an .mdb file, imports an identically structured table from a .mde file,
runs an append query I have in place to copy the data from the imported
table to the table in my.mbd file, and then delete the imported table.

Any help that could be provided would be greatly appreciated.

Best wishes,

George Hadley
(e-mail address removed)
 
R

Roger Carlson

Sure. But I wouldn't import it then delete it. I'd Link it instead.

You didn't give any table or field names, so I made up my own. Try
something like this:

Sub UpdateTableX()
Dim strSQL
strSQL = "Delete * from TableX"
CurrentDb.Execute strSQL

DoCmd.TransferDatabase acLink, "Microsoft Access", _
"C:\PATH\TO\IMPORT\FILE.mde", acTable, _
"TableX", "TableXtemp", False

strSQL = "INSERT INTO TableX ( ID, FieldX1, FieldX2, FieldX3 )" & _
"SELECT ID, FieldX1, FieldX2, FieldX3 " & _
"FROM TableXtemp;"
CurrentDb.Execute strSQL

strSQL = "DROP TABLE TableXtemp"
CurrentDb.Execute strSQL
End Sub

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 

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