Solved

Import multiple tables using: DoCmd.TransferDatabase acImport

Posted on 2003-11-11
7
2,257 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now