473,394 Members | 2,048 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,394 software developers and data experts.

TransferDatabase wont kick-start!

Hi guys,

Using Access 2003 on XP.

First time caller, long time listener. I am not a programmer per se,
and all my training in coding in the past year or so has come from the
wealth of info in these newsgroups, but I've finally hit a brick wall
re importing tables from one Access db to another.

I have set up an import routine that loops through db's in a specified
folder, importing selected tables from each to a consolidated db. The
thing is, the code I have below does work to some extent, but only
does so once I have "manually" imported any table from any db in the
folder I am calling on (ie - going through the File -> External Data
-> Import method). It seems to spark it somehow or finds the right
place to look ....but if I dont do this, it appears that the file I am
searching for "cant be found" as such (even though it can still count
how many files are in the folder with the first part of my code), but
once it hits the TransferDatabase part of the code, it just stops.

From other similar posts, the only thing I can glean is that I may
have to set up a Workspace or have an OpenDatabase command first so
the db can be "found"? Strange one that is a bit beyond my
guesstimation as a "non-coder".

Would appreciate any ideas ...the relevant code is posted below...

Private Sub btn_Import_Click()

Dim filename As String
Dim myFileCount As Integer

On Error GoTo Err_Section

filename = Dir("C:\Data\*.mdb") 'want all the Access files in this
dir

'Count the number of Access files in this directory
With Application.FileSearch
..Lookin = "C:\Data"
..SearchSubFolders = False
..filename = "*.mdb"
..Execute
myFileCount = .FoundFiles.Count

' If no files then give msg and get out
If myFileCount = 0 Then
MsgBox "No databases to import", vbInformation, MsgBoxTitle
Exit Sub

'Else away we go, display number of files we are importing in MsgBox
Else
MsgBox "You are about to import " & myFileCount & " databases into the
consolidated Dbase ", vbInformation
End If
End With

' Begin data transfer of Access files
Do While Len(filename) > 0 'start of loop

' Show on user form what file is currently being imported
Me.txt_Status = "Importing tables from " & filename '
Me.Repaint

'''''' Routine stops running here

DoCmd.TransferDatabase acImport, "Microsoft Access", filename, _
acTable, "tbl_EQUIPMENT_H", "tmp_tbl_EQUIPMENT_H"

DoCmd.TransferDatabase acImport, "Microsoft Access", filename, _
acTable, "tbl_EQUIPMENT_D", "tmp_tbl_EQUIPMENT_D"

.....Other stuff..... appending data queries, dropping tmp tables
etc...

filename = Dir 'go to next Access file in loop
Loop

End Sub

Cheers,
Dave G
Melb, Aust
Nov 13 '05 #1
6 1974
Hi Dave

This should list the tables in another database without OpenDatabase():
SELECT MSysObjects.Name
FROM MSysObjects IN 'C:\Data\MyFile.mdb'
WHERE (MSysObjects.Type = 1) AND NOT
((MSysObjects.Name Like '~*') Or (MSysObjects.Name Like 'MSys*'));

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Dave Gehrig" <da**********************@hotmail.com> wrote in message
news:92*************************@posting.google.co m...
Hi guys,

Using Access 2003 on XP.

First time caller, long time listener. I am not a programmer per se,
and all my training in coding in the past year or so has come from the
wealth of info in these newsgroups, but I've finally hit a brick wall
re importing tables from one Access db to another.

I have set up an import routine that loops through db's in a specified
folder, importing selected tables from each to a consolidated db. The
thing is, the code I have below does work to some extent, but only
does so once I have "manually" imported any table from any db in the
folder I am calling on (ie - going through the File -> External Data
-> Import method). It seems to spark it somehow or finds the right
place to look ....but if I dont do this, it appears that the file I am
searching for "cant be found" as such (even though it can still count
how many files are in the folder with the first part of my code), but
once it hits the TransferDatabase part of the code, it just stops.

From other similar posts, the only thing I can glean is that I may
have to set up a Workspace or have an OpenDatabase command first so
the db can be "found"? Strange one that is a bit beyond my
guesstimation as a "non-coder".

Would appreciate any ideas ...the relevant code is posted below...

Private Sub btn_Import_Click()

Dim filename As String
Dim myFileCount As Integer

On Error GoTo Err_Section

filename = Dir("C:\Data\*.mdb") 'want all the Access files in this
dir

'Count the number of Access files in this directory
With Application.FileSearch
.Lookin = "C:\Data"
.SearchSubFolders = False
.filename = "*.mdb"
.Execute
myFileCount = .FoundFiles.Count

' If no files then give msg and get out
If myFileCount = 0 Then
MsgBox "No databases to import", vbInformation, MsgBoxTitle
Exit Sub

'Else away we go, display number of files we are importing in MsgBox
Else
MsgBox "You are about to import " & myFileCount & " databases into the
consolidated Dbase ", vbInformation
End If
End With

' Begin data transfer of Access files
Do While Len(filename) > 0 'start of loop

' Show on user form what file is currently being imported
Me.txt_Status = "Importing tables from " & filename '
Me.Repaint

'''''' Routine stops running here

DoCmd.TransferDatabase acImport, "Microsoft Access", filename, _
acTable, "tbl_EQUIPMENT_H", "tmp_tbl_EQUIPMENT_H"

DoCmd.TransferDatabase acImport, "Microsoft Access", filename, _
acTable, "tbl_EQUIPMENT_D", "tmp_tbl_EQUIPMENT_D"

....Other stuff..... appending data queries, dropping tmp tables
etc...

filename = Dir 'go to next Access file in loop
Loop

End Sub

Cheers,
Dave G
Melb, Aust

Nov 13 '05 #2
Thanks for the response Allen ...been a fan of your work for a long
time!

Re your suggestion, I'm not exactly sure where I should be putting it
within my code, and what else I need to go with it. Given I only have
to import certain tables from each db that I am looping through, is
"listing" all the tables as you mention below still the way to go
about it?

Might have to walk me through this one mate!

Cheers,
Dave G

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message news:<41***********************@per-qv1-newsreader-01.iinet.net.au>...
Hi Dave

This should list the tables in another database without OpenDatabase():
SELECT MSysObjects.Name
FROM MSysObjects IN 'C:\Data\MyFile.mdb'
WHERE (MSysObjects.Type = 1) AND NOT
((MSysObjects.Name Like '~*') Or (MSysObjects.Name Like 'MSys*'));

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

Nov 13 '05 #3
Hi Dave

Okay, re-reading your message, the issue is not that you can't get the
tables in each database, but that they don't import?

Not sure why that would be the case. If the tables are actually there (not
merely attached tables), you should be able to import. Once you've done it
once, do you have an attached table as a result or something?

The idea of the IN clause in the SQL statement may be useful anyway. You may
be able to create an Append query using the IN clause to specify the source
database instead of the TransferDatabase.

You should not have to OpenDatabase. In point of fact, you may get a
performance gain if you are importing lots of tables, but that's just
because Windows is holding the file open instead of opening and closing it;
the process doesn't need the OpenDatabase.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Dave Gehrig" <da**********************@hotmail.com> wrote in message
news:92**************************@posting.google.c om...
Thanks for the response Allen ...been a fan of your work for a long
time!

Re your suggestion, I'm not exactly sure where I should be putting it
within my code, and what else I need to go with it. Given I only have
to import certain tables from each db that I am looping through, is
"listing" all the tables as you mention below still the way to go
about it?

Might have to walk me through this one mate!

Cheers,
Dave G
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:<41***********************@per-qv1-newsreader-01.iinet.net.au>...
Hi Dave

This should list the tables in another database without OpenDatabase():
SELECT MSysObjects.Name
FROM MSysObjects IN 'C:\Data\MyFile.mdb'
WHERE (MSysObjects.Type = 1) AND NOT
((MSysObjects.Name Like '~*') Or (MSysObjects.Name Like
'MSys*'));

Nov 13 '05 #4
Thanks Allen....

It seems a bit of a strange one, as my code does work (eventually),
but only does so AFTER I have imported a table through the
stock-standard menu File -> Get External Data -> Import method (ie -
if I manually just import any table from one of my d'base's in the
loop folder, I can then go back to the code itself to run the whole
batch from there and it works no problems).

However, if I close my consolidated dbase and re-open it, the routine
again wont run without doing the above first, as it drops out just
before its about to import that first table in the first loop (despite
it still being able to count the number of files in the loop folder!).
Again, if I do the manual import, the code can then be run
successfully.

So I guess the issue is, what is stopping the routine from being able
to import ...but can then trigger itself to work somehow after a
"manual" table import?

I'm gazumped!

Dave

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message news:<41***********************@per-qv1-newsreader-01.iinet.net.au>...
Hi Dave

Okay, re-reading your message, the issue is not that you can't get the
tables in each database, but that they don't import?

Not sure why that would be the case. If the tables are actually there (not
merely attached tables), you should be able to import. Once you've done it
once, do you have an attached table as a result or something?

The idea of the IN clause in the SQL statement may be useful anyway. You may
be able to create an Append query using the IN clause to specify the source
database instead of the TransferDatabase.

You should not have to OpenDatabase. In point of fact, you may get a
performance gain if you are importing lots of tables, but that's just
because Windows is holding the file open instead of opening and closing it;
the process doesn't need the OpenDatabase.

Nov 13 '05 #5
Any issues with permissions?

If you want to try the OpenDatabase idea, it's quite simple:
Dim dbData as DAO.Database
Set dbData = OpenDatabase("C:\MyFolder\MyFile.mdb")
'useful stuff in here.
dbData.Close

BTW, how long is the path here? If it's 128 characters or more, that can
have a detrimental effect.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Dave Gehrig" <da**********************@hotmail.com> wrote in message
news:92**************************@posting.google.c om...
Thanks Allen....

It seems a bit of a strange one, as my code does work (eventually),
but only does so AFTER I have imported a table through the
stock-standard menu File -> Get External Data -> Import method (ie -
if I manually just import any table from one of my d'base's in the
loop folder, I can then go back to the code itself to run the whole
batch from there and it works no problems).

However, if I close my consolidated dbase and re-open it, the routine
again wont run without doing the above first, as it drops out just
before its about to import that first table in the first loop (despite
it still being able to count the number of files in the loop folder!).
Again, if I do the manual import, the code can then be run
successfully.

So I guess the issue is, what is stopping the routine from being able
to import ...but can then trigger itself to work somehow after a
"manual" table import?

I'm gazumped!

Dave
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message

news:<41***********************@per-qv1-newsreader-01.iinet.net.au>...
Hi Dave

Okay, re-reading your message, the issue is not that you can't get the
tables in each database, but that they don't import?

Not sure why that would be the case. If the tables are actually there
(not
merely attached tables), you should be able to import. Once you've done
it
once, do you have an attached table as a result or something?

The idea of the IN clause in the SQL statement may be useful anyway. You
may
be able to create an Append query using the IN clause to specify the
source
database instead of the TransferDatabase.

You should not have to OpenDatabase. In point of fact, you may get a
performance gain if you are importing lots of tables, but that's just
because Windows is holding the file open instead of opening and closing
it;
the process doesn't need the OpenDatabase.

Nov 13 '05 #6
I finally got the thing going, didnt have to resort to OpenDatabase.

Your mentioning of the path name got me thinking to fully specify the
loop folder path in the TransferDatabase line to get it going, eg:

DoCmd.TransferDatabase acImport, "Microsoft Access", "C:\Data\" &
filename, _
acTable, "tbl_Equipment_H", "tmp_tbl_Equipment_H"

If I had previously manually imported a table from this folder, I
didnt have to put the "C:\Data\" part in the path to get the thing
going ...was as though the applic had already located the folder it
was looking for, so didnt have to "look" again? ...dunno, still can't
explain that part of it! ...but it's problem solved nonetheless.

For interest sake, the actual path I am calling from in my applic is
longer than 128 char's and it still works ok.

Thanks for your input here Allen.

Cheers,
Dave G
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message news:<41***********************@per-qv1-newsreader-01.iinet.net.au>...
Any issues with permissions?

If you want to try the OpenDatabase idea, it's quite simple:
Dim dbData as DAO.Database
Set dbData = OpenDatabase("C:\MyFolder\MyFile.mdb")
'useful stuff in here.
dbData.Close

BTW, how long is the path here? If it's 128 characters or more, that can
have a detrimental effect.

Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jer | last post by:
I am trying to export the results of a view from an .adp to an .mdb using TransferDatabase. The code I am using is DoCmd.TransferDatabase acExport, "Microsoft Access", _...
0
by: KJones | last post by:
Here is the setup There are three Machines all running Access97 & XP Pro \\readingtill1 \\redingback \\redingtill2 on a LAN And four dbs
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: Pachydermitis | last post by:
Hi all, I am trying to use transferdatabase to link tables to a shared backend. If someone is already using the back end, transferdatabase tries to lock the table and causes an error. Is there...
1
by: Jens Hofmeier | last post by:
Hello, i want to transfer a table from database sourceMDB to a password protected database named destMDB. I was not able to figure out where to specify the required password ind the parameters...
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...
1
by: Danny J. Lesandrini | last post by:
Does anyone know if it's possible to use TransferDatabase to export data to MySQL? If not, how would one go about it? Below is the code I tried to use, but it doesn't work. sTable = "tblLead"...
1
by: solar | last post by:
In copying tables i use the command Transferdatabase shown below.It is a good command, but i need the following refinement. I want to copy the table only when the Yes/No field "accepted" in the...
1
by: acdevteam | last post by:
Hi, I have a question about TransferDatabase. I am using the following code, that works great: strDBFPath = "\\servername\folder" strDBFFile = "Master" DoCmd.TransferDatabase acImport,...
3
by: Mogsey | last post by:
Dear All, I have what is likely to be a very small problem for an Access guru, connecting to an ODBC database in VBA in Access 2002. I recieve an error code of 3151 ODBC Connection to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.