Automate file import

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to automate File > get external data > import
I want to build a new smaller app from the main app and import most but not
all objects to a new mdb. Can I automate that?
Thanks!!
 
Yes, you can. Here is an example of exporting all your queries. I know you
want to import, but just change the syntax as needed (See TransferDatabase
Method in HelpP. This should serve as an example of how to import your other
objects.
For i = 0 To mydb.QueryDefs.Count - 1
DoCmd.TransferDatabase acExport, "Microsoft Access", todb, acQuery,
mydb.QueryDefs(i).Name, mydb.QueryDefs(i).Name
Next i
 
I would create a table tha contain two fields, Object Name and Object Type,
fill the table with the name of the objects I want to transfer.
Create a function that imports all the objects, based on the table

Object Type = acForm , acTable etc

Function ImportObjects()
Dim MyDb as database, MyRec as recordset
Set MyDb=Codedb
Set MyRec = MyDb.openrecordset("TableName")
While not myrec.eof
docmd.TransferDatabase acImport,,"Mdb Name And
Path",Myrec!ObjectType,Myrec!ObjectName,Myrec!ObjectName
myrec.movenext
Wend

End Function
 
A workable solution, Ofer, but see my previous post, creating and reading the
table are not necessary.
 
Thanks
That make sense but Sam asked not to import all the objects, and this is why
I gave the option of creating a table with the list of the objects he wants
to import.
 
Cool guys!
I can use a combo of both posts because I want all queries but selected
forms. So I could store the specific forms in a table.

Thanks,
Sam
 
Back
Top