Solved

Import multiple tables using: DoCmd.TransferDatabase acImport

Posted on 2003-11-11
7
2,344 Views
Last Modified: 2007-12-19
dexweaver wrote the following code, I am using it and it works like a charm:

Okay, make a table (tblTableNames) with one field (TableName), put the names of the tables in one per line, then use some code like this:

'*******************************************
Dim r as Recordset
Dim CurrentTableName as String

Set r = CurrentDb.OpenRecordset("tblTableNames")

r.MoveFirst
Do Until r.EOF
  CurrentTableName = r!TableName
  If IsTable(CurrentTableName Then
    DoCmd.DeleteObject acTable, CurrentTableName
  End If
Loop
'*******************************************
What I would like now is to import the same tables that have been deleted using DoCmd.TransferDatabase acImport without having to type all the tables. In other words, using the same type of script.
Thanks,
Gabe

0
Comment
Question by:gablais
  • 4
  • 3
7 Comments
 
LVL 32

Expert Comment

by:jadedata
ID: 9726349
Hey gablais!

  using your same tblTableNames, add a field for the Make-Table query name that is built to re-build the table.
  Be aware that the Query is going to have certain requirements that you will have to deal with that I have no idea about

Dim r as Recordset
Dim CurrentQueryName as String

Set r = CurrentDb.OpenRecordset("tblTableNames")

r.MoveFirst
Do Until r.EOF
  CurrentQueryName = r!QueryName
  If Not IsTable(r!TableName) Then
    docmd.runsql CurrentQueryName
  End If
Loop



regards
Jack
0
 

Author Comment

by:gablais
ID: 9726470
Jack, I am not sure we are on the same page. The task I am trying to accomplish is to import tables from another database. The name of the tables will be the same on both databases.
If I had only one table to import it would be something like this:
DoCmd.TransferDatabase acImport, "Microsoft Access", "S:\HES\Safety & IH Databases\Checklist.mdb", acTable, "Air_Quality", "Air_Quality"

But I have nearly 80 of them.

Please let me know If I am being clear enough.
Gabe
0
 
LVL 32

Expert Comment

by:jadedata
ID: 9726502
In that case make the new field the path to the database you are importing from (see r!DatabaseName below)

Dim r as Recordset
Set r = CurrentDb.OpenRecordset("tblTableNames")
r.MoveFirst
Do Until r.EOF
  If Not IsTable(r!TableName) Then
    DoCmd.TransferDatabase acImport, "Microsoft Access", r!DatabaseName, acTable, r!TableName, r!TableName
  End If
Loop
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:gablais
ID: 9726787
Ok Jack, We're getting there.
The loop is getting carried away and keeps reimporting the first table until I kill the application.
Also, I don't think I need the following lines in that script:
If Not IsTable(r!TableName) Then
End If
If I do use them, the table does not import more than once, but the loop does not stop running.
Gabe
0
 
LVL 32

Accepted Solution

by:
jadedata earned 500 total points
ID: 9726874
Dim r as Recordset
Set r = CurrentDb.OpenRecordset("tblTableNames")
r.MoveFirst
Do Until r.EOF
  If Not IsTable(r!TableName) Then
    DoCmd.TransferDatabase acImport, "Microsoft Access", r!DatabaseName, acTable, r!TableName, r!TableName
  End If
  r.movenext
Loop

Now remeber I started this copy with your first code block.
Added the r.movenext to get it to move to the next record.  Can't get to the EOF unless you traverse records!
0
 

Author Comment

by:gablais
ID: 9726901
You got it pal. Thank you and take care.
Gabe
0
 
LVL 32

Expert Comment

by:jadedata
ID: 9726912
and thank you for the question!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question