473,416 Members | 1,550 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

DoCmd.TransferDatabase - use a variable for source

Attached is code to link tables in databases that are in a folder. My variable for the source in the DoCmd.transferDatabase code Dir(strPath & rst!FolderName) is not working right. I want to loop through the db names to link the tables.

each db has only 1 table which is named the same as the db. We have a macro that pulls all the db names from the folder into a table called tblDirectory into the field FolderName (that's a bit misleading, I know). I have very little VB knowledge. I'd appreciate any detailed instructions.

Expand|Select|Wrap|Line Numbers
  1. Function LinkTable()
  2.  
  3. Dim rst As DAO.Recordset
  4. Dim strPath As String
  5. Dim strFile As String
  6.  
  7.   strPath = "D:\Temp\Testing\"
  8.  
  9. Set rst = CurrentDb.OpenRecordset("tblDirectory", dbOpenTable)
  10. Do Until rst.EOF
  11.      'ensure exist
  12.        strFile = Dir(strPath & rst!FolderName)
  13.       If Len(Dir(strPath & rst!FolderName)) > 0 Then
  14.             DoCmd.TransferDatabase acLink, "Microsoft Access", Dir(strPath & rst!FolderName), acTable, rst!FolderName, rst!FolderName, False
  15.             End If
  16.     rst.MoveNext
  17. Loop
  18. rst.Close
  19. Set rst = Nothing
  20.  
  21. End Function
  22.  
Sep 12 '14 #1

✓ answered by jforbes

The picture is getting clearer. I would guess the File is being found since you are getting past line 13 which is testing for it's existence. I should have realized that if that was working, the file extension is included in rst!FolderName.

So since the Extension is in FolderName, it should be stripped out when referring to the tables. You might want to try this for line 14:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferDatabase acLink, "Microsoft Access", strPath & rst!FolderName, acTable, Left(rst!FolderName, InStr(rst!FolderName, ".") - 1), Left(rst!FolderName, InStr(rst!FolderName, ".") - 1), False
If it works, it might be best to go back and clean it up by putting table name into a string of it's own.

10 7941
jforbes
1,107 Expert 1GB
I didn't see anything glaring obviously wrong with the code, so it would be nice to know how it is not working right. What error are you getting?
Sep 12 '14 #2
access says, "error 3024, cannot find the file..." and displays the path of my default folder (the documents folder) and the name of the first db in the list. thank you for looking.
Sep 12 '14 #3
after clicking debug access stops on the line DoCmd.TransferDatabase acLink, "Microsoft Access", Dir("D:\Temp\Testing\" & rst!FolderName) etc
Sep 12 '14 #4
jforbes
1,107 Expert 1GB
I think line 14 should be:
Expand|Select|Wrap|Line Numbers
  1.             DoCmd.TransferDatabase acLink, "Microsoft Access", strPath & rst!FolderName, acTable, rst!FolderName, rst!FolderName, False
  2.  
Sep 12 '14 #5
unfortunately that did not do it. I get a message that access database engine could not find the object... and lists the first db name in the table. here's the current code:
Expand|Select|Wrap|Line Numbers
  1. Function LinkTable()
  2.  
  3. Dim rst As DAO.Recordset
  4. Dim strPath As String
  5. Dim strFile As String
  6.  
  7.   strPath = "D:\Temp\Testing\"
  8.  
  9. Set rst = CurrentDb.OpenRecordset("tblDirectory", dbOpenTable)
  10. Do Until rst.EOF
  11.      'ensure exist
  12.        strFile = Dir(strPath & rst!FolderName)
  13.       If Len(Dir(strPath & rst!FolderName)) > 0 Then
  14.             DoCmd.TransferDatabase acLink, "Microsoft Access", strPath & rst!FolderName, acTable, rst!FolderName, rst!FolderName, False
  15.             'DoCmd.TransferDatabase acLink, "Microsoft Access", Dir("D:\Temp\Testing\" & rst!FolderName), acTable, rst!FolderName, rst!FolderName, False
  16.             End If
  17.     rst.MoveNext
  18. Loop
  19. rst.Close
  20. Set rst = Nothing
  21. End Function
  22.  
Sep 12 '14 #6
jforbes
1,107 Expert 1GB
Here is the examples from Microsoft on the
Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferDatabase:
  2. DoCmd.TransferDatabase acImport, "Microsoft Access", _ 
  3.     "C:\My Documents\NWSales.mdb", acReport, "NW Sales for April", _ 
  4.     "Corporate Sales for April"
  5.  
  6. DoCmd.TransferDatabase acLink, "ODBC Database", _ 
  7.     "ODBC;DSN=DataSource1;UID=User2;PWD=www;LANGUAGE=us_english;" _
  8.     & "DATABASE=pubs", acTable, "Authors", "dboAuthors"
When they refer to an Access database the full Database Name is listed, including “.MDB”. I have a feeling that may need to be included as well. So maybe Line 14 should be:
Expand|Select|Wrap|Line Numbers
  1.             DoCmd.TransferDatabase acLink, "Microsoft Access", strPath & rst!FolderName & “.mdb”, acTable, rst!FolderName, rst!FolderName, False
  2.  
Sep 12 '14 #7
thanks again. the .accdb is included in the table (see below):

FolderName
AUTH.accdb
MONTHS.accdb
PHASE.accdb
ACCT_LST.accdb
Sep 12 '14 #8
actually, access tells me the first table name, it says it can't find the folder. so it's having problems finding the actual location
Sep 12 '14 #9
jforbes
1,107 Expert 1GB
The picture is getting clearer. I would guess the File is being found since you are getting past line 13 which is testing for it's existence. I should have realized that if that was working, the file extension is included in rst!FolderName.

So since the Extension is in FolderName, it should be stripped out when referring to the tables. You might want to try this for line 14:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferDatabase acLink, "Microsoft Access", strPath & rst!FolderName, acTable, Left(rst!FolderName, InStr(rst!FolderName, ".") - 1), Left(rst!FolderName, InStr(rst!FolderName, ".") - 1), False
If it works, it might be best to go back and clean it up by putting table name into a string of it's own.
Sep 12 '14 #10
wooohooo!! thank you!!! worked!!
Sep 12 '14 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: dixie | last post by:
I am using the Docmd.TransferDatabase to transfer part of a table into another smaller database. The source comes from a select query that transfers the part of the table that I need. The...
2
by: AccessStarters | last post by:
I am trying to Import a simple dbase file into my Ak2 TABLES. If I do this manually, it works fine. I get a new table called DBASE with all the data looking good. If I try and do this using VBA...
0
by: astro | last post by:
I'm trying to copy some ODBC linked tables from one access2k mdb to another. This is an example of the code i'm using: DoCmd.TransferDatabase acExport, "Microsoft Access", (strPath & strTemp),...
1
by: clusardi2k | last post by:
In chapter 23, it explains how to navigate the tables of a DataSet. I'm looking for the definition of "AllOrders1", below. I.E.: How is it created, explained to me in a step by step fashion, and...
3
Minion
by: Minion | last post by:
I hate to even post this message as I probably know the answer before I begin. Still there are several problems facing me with this particular challenge. First though I'll goto into the overview...
1
by: amitkumar19 | last post by:
hello dear when i use this statements in vb6 for transfer data to one another DoCmd.TransferDatabase acImport, "dBase III", "C:\Data", acTable, _ "Test112A.dbf", "TempFile" then give a error...
1
by: amitkumar19 | last post by:
hello dear when i use this statements in vb6 for transfer data to one another DoCmd.TransferDatabase acImport, "dBase III", "C:\Data", acTable, _ "Test112A.dbf", "TempFile" then give a error...
3
by: chris.spano | last post by:
I'm running Access 2003 on an XP machine, and there are multiple developers who are working on different "assignments" of our large database project. We all work on a local copy and export changes...
4
by: ncsthbell | last post by:
I am using MS2007 on windows XP. I support an access application which has a 'main menu' (form) and on this form there is a button 'Exit Database'. In the 'on click' event code for the 'Exit...
1
by: albertob | last post by:
Hello! I have the following problem. I'm trying to use an ODBC connection to import one table from an ORACLE database to my access database. Manually, trough access command panel database ODBC,...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.