Solved

Import multiple tables using: DoCmd.TransferDatabase acImport

Posted on 2003-11-11
7
2,323 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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 …

838 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