Solved

Import multiple tables using: DoCmd.TransferDatabase acImport

Posted on 2003-11-11
7
2,297 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

786 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