dbTalk Databases Forums  

Import DBF files to Access 2003

comp.databases.ms-access comp.databases.ms-access


Discuss Import DBF files to Access 2003 in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Aileen Turner
 
Posts: n/a

Default Import DBF files to Access 2003 - 08-12-2010 , 03:14 PM






I have hundreds of dbf files to import from a folder to a table in access
2003
and or 2007. At present I import each file as a table then copy and paste
to a
master table. For other imports (text, excel etc) I have a macro to import
all
files in a folder, but I have no option to import DBF files, Anyone able to
advise?.
TIA
taxi data

Reply With Quote
  #2  
Old   
Chuck Grimsby
 
Posts: n/a

Default Re: Import DBF files to Access 2003 - 08-14-2010 , 08:31 AM






On Aug 12, 3:14*pm, "Aileen Turner" <taxiail... (AT) yahoo (DOT) com.au> wrote:
Quote:
I have hundreds of dbf files to import from a folder to a table in access
2003 and or 2007. *At present I import each file as a table then copy and paste
to a master table. For other imports (text, excel etc) I have a macro to import
all files in a folder, but I have no option to import DBF files, *Anyone able to
advise?.
Why not just link to the DBF files and run a import query against the
file? Drop the link when you're done, then move on to the next.

You can also do this for the text and excel files....

Reply With Quote
  #3  
Old   
Taxi Aileen
 
Posts: n/a

Default Re: Import DBF files to Access 2003 - 08-14-2010 , 02:54 PM



Unfortunately I am unable to link to the files. There is a separate file
for each day. I can copy each file from the server to a folder on my
computer. I then need to import each file to access. I need to do this for
every day of 2009.
I have a an import macro (copied from a newsgroup years ago) to import all
text file in a folder, then run and append query to append the master table
and I was hoping to find something similar for DBF files.

"Chuck Grimsby" <cgatgoo (AT) gmail (DOT) com> wrote

On Aug 12, 3:14 pm, "Aileen Turner" <taxiail... (AT) yahoo (DOT) com.au> wrote:
Quote:
I have hundreds of dbf files to import from a folder to a table in access
2003 and or 2007. At present I import each file as a table then copy and
paste
to a master table. For other imports (text, excel etc) I have a macro to
import
all files in a folder, but I have no option to import DBF files, Anyone
able to
advise?.
Why not just link to the DBF files and run a import query against the
file? Drop the link when you're done, then move on to the next.

You can also do this for the text and excel files....

Reply With Quote
  #4  
Old   
Salad
 
Posts: n/a

Default Re: Import DBF files to Access 2003 - 08-14-2010 , 10:08 PM



Taxi Aileen wrote:
Quote:
Unfortunately I am unable to link to the files. There is a separate
file for each day. I can copy each file from the server to a folder on
my computer. I then need to import each file to access. I need to do
this for every day of 2009.
I have a an import macro (copied from a newsgroup years ago) to import
all text file in a folder, then run and append query to append the
master table and I was hoping to find something similar for DBF files.
Here's a sample sub to scan all files in the folder.
Sub ScanDBFFilesInFolder(strFolder As String)
Dim s As String

If Right(strFolder, 1) <> "\" Then strFolder = strFolder & "\"

'find first dbf file
s = Dir(strFolder & "*.dbf")

Do While s > ""

Debug.Print s

'find next dbf file
s = Dir()
Loop
MsgBox "Done. All dbfs viewed"
End Sub

If you can import them, you can link to them. I assume your are doing
it by hand. That has to be a drag.
Docmd.TransferDatabase acLink, "dBase III",...

Here's an example from Help
DoCmd.TransferDatabase acImport, "Microsoft Access", _
"C:\My Documents\NWSales.mdb", acReport, "NW Sales for April", _
"Corporate Sales for April"

You might have to futz with it, try different types, but if you are
doing it manually you'll know which database type to use.

You'd then run that acLink, then the query to append, prior to the
s=Dir() line. I'd recommend you have make a copy before running and
doing testing of the mdb that has the backend tables.




Quote:
"Chuck Grimsby" <cgatgoo (AT) gmail (DOT) com> wrote in message
news:001a8d1e-24f5-4a6e-ae9a-6883088acbb4 (AT) s9g2000yqd (DOT) googlegroups.com...
On Aug 12, 3:14 pm, "Aileen Turner" <taxiail... (AT) yahoo (DOT) com.au> wrote:

I have hundreds of dbf files to import from a folder to a table in access
2003 and or 2007. At present I import each file as a table then copy
and paste
to a master table. For other imports (text, excel etc) I have a macro
to import
all files in a folder, but I have no option to import DBF files,
Anyone able to
advise?.


Why not just link to the DBF files and run a import query against the
file? Drop the link when you're done, then move on to the next.

You can also do this for the text and excel files....

Reply With Quote
  #5  
Old   
Chuck Grimsby
 
Posts: n/a

Default Re: Import DBF files to Access 2003 - 08-15-2010 , 12:22 PM



On Aug 14, 10:08*pm, Salad <sa... (AT) oilandvinegar (DOT) com> wrote:
Quote:
Taxi Aileen wrote:
Unfortunately I am unable to link to the files. *There is a separate
file for each day. *I can copy each file from the server to a folder on
my computer. I then need to import each file to access. *I need to do
this for every day of 2009.
I have a an import macro (copied from a newsgroup years ago) to import
all text file in a folder, then run and append query to append the
master table and I was hoping to find something similar for DBF files.

Here's a sample sub to scan all files in the folder.
Sub ScanDBFFilesInFolder(strFolder As String)
* * *Dim s As String

* * *If Right(strFolder, 1) <> "\" Then strFolder = strFolder & "\"

* * *'find first dbf file
* * *s = Dir(strFolder & "*.dbf")

* * *Do While s > ""

* * * * *Debug.Print s

* * * * *'find next dbf file
* * * * *s = Dir()
* * *Loop
* * *MsgBox "Done. *All dbfs viewed"
End Sub

If you can import them, you can link to them. *I assume your are doing
it by hand. *That has to be a drag.
* * * * Docmd.TransferDatabase acLink, "dBase III",...

Here's an example from Help
DoCmd.TransferDatabase acImport, "Microsoft Access", _
* * *"C:\My Documents\NWSales.mdb", acReport, "NW Sales for April",_
* * *"Corporate Sales for April"

You might have to futz with it, try different types, but if you are
doing it manually you'll know which database type to use.

You'd then run that acLink, then the query to append, prior to the
s=Dir() line. *I'd recommend you have make a copy before running and
doing testing of the mdb that has the backend tables.





"Chuck Grimsby" <cgat... (AT) gmail (DOT) com> wrote in message
news:001a8d1e-24f5-4a6e-ae9a-6883088acbb4 (AT) s9g2000yqd (DOT) googlegroups.com...
On Aug 12, 3:14 pm, "Aileen Turner" <taxiail... (AT) yahoo (DOT) com.au> wrote:

I have hundreds of dbf files to import from a folder to a table in access
2003 and or 2007. At present I import each file as a table then copy
and paste
to a master table. For other imports (text, excel etc) I have a macro
to import
all files in a folder, but I have no option to import DBF files,
Anyone able to
advise?.

Why not just link to the DBF files and run a import query against the
file? *Drop the link when you're done, then move on to the next.
You can also do this for the text and excel files....
Good code Salad!

Since you can just link to the DBFs, rather then doing a Transfer, I'd
suggest just doing that, linking rather then importing. Often what I
see is that programmers import everything then run a series of queries
against the imported data to get whatever they need in the format they
need it in. A lot of work for little return. Instead, if they just
link to the data, often a query or two can do all of that in one
procedure. So rather then TransferDatabase, it's often better to link
to the data as if it were a seperate table (since it already is) via
the CreateTableDef command, and just do whatever query(s) are needed.
Faster and less repeated work for each link each time the data is
imported.

This works for Excel and CSV or TSV files as well as DBFs. Just
remember you can't do update queries on these files!

Reply With Quote
  #6  
Old   
R & A Turner
 
Posts: n/a

Default Re: Import DBF files to Access 2003 - 08-15-2010 , 02:04 PM



Thank you Salad and Chuck.... Just what I was looking for!!!
Aileen
"Chuck Grimsby" <cgatgoo (AT) gmail (DOT) com> wrote

On Aug 14, 10:08 pm, Salad <sa... (AT) oilandvinegar (DOT) com> wrote:
Quote:
Taxi Aileen wrote:
Unfortunately I am unable to link to the files. There is a separate
file for each day. I can copy each file from the server to a folder on
my computer. I then need to import each file to access. I need to do
this for every day of 2009.
I have a an import macro (copied from a newsgroup years ago) to import
all text file in a folder, then run and append query to append the
master table and I was hoping to find something similar for DBF files.

Here's a sample sub to scan all files in the folder.
Sub ScanDBFFilesInFolder(strFolder As String)
Dim s As String

If Right(strFolder, 1) <> "\" Then strFolder = strFolder & "\"

'find first dbf file
s = Dir(strFolder & "*.dbf")

Do While s > ""

Debug.Print s

'find next dbf file
s = Dir()
Loop
MsgBox "Done. All dbfs viewed"
End Sub

If you can import them, you can link to them. I assume your are doing
it by hand. That has to be a drag.
Docmd.TransferDatabase acLink, "dBase III",...

Here's an example from Help
DoCmd.TransferDatabase acImport, "Microsoft Access", _
"C:\My Documents\NWSales.mdb", acReport, "NW Sales for April", _
"Corporate Sales for April"

You might have to futz with it, try different types, but if you are
doing it manually you'll know which database type to use.

You'd then run that acLink, then the query to append, prior to the
s=Dir() line. I'd recommend you have make a copy before running and
doing testing of the mdb that has the backend tables.





"Chuck Grimsby" <cgat... (AT) gmail (DOT) com> wrote in message
news:001a8d1e-24f5-4a6e-ae9a-6883088acbb4 (AT) s9g2000yqd (DOT) googlegroups.com...
On Aug 12, 3:14 pm, "Aileen Turner" <taxiail... (AT) yahoo (DOT) com.au> wrote:

I have hundreds of dbf files to import from a folder to a table in
access
2003 and or 2007. At present I import each file as a table then copy
and paste
to a master table. For other imports (text, excel etc) I have a macro
to import
all files in a folder, but I have no option to import DBF files,
Anyone able to
advise?.

Why not just link to the DBF files and run a import query against the
file? Drop the link when you're done, then move on to the next.
You can also do this for the text and excel files....
Good code Salad!

Since you can just link to the DBFs, rather then doing a Transfer, I'd
suggest just doing that, linking rather then importing. Often what I
see is that programmers import everything then run a series of queries
against the imported data to get whatever they need in the format they
need it in. A lot of work for little return. Instead, if they just
link to the data, often a query or two can do all of that in one
procedure. So rather then TransferDatabase, it's often better to link
to the data as if it were a seperate table (since it already is) via
the CreateTableDef command, and just do whatever query(s) are needed.
Faster and less repeated work for each link each time the data is
imported.

This works for Excel and CSV or TSV files as well as DBFs. Just
remember you can't do update queries on these files!

Reply With Quote
  #7  
Old   
Salad
 
Posts: n/a

Default Re: Import DBF files to Access 2003 - 08-15-2010 , 03:09 PM



Chuck Grimsby wrote:
Quote:
On Aug 14, 10:08 pm, Salad <sa... (AT) oilandvinegar (DOT) com> wrote:

Taxi Aileen wrote:

Unfortunately I am unable to link to the files. There is a separate
file for each day. I can copy each file from the server to a folder on
my computer. I then need to import each file to access. I need to do
this for every day of 2009.
I have a an import macro (copied from a newsgroup years ago) to import
all text file in a folder, then run and append query to append the
master table and I was hoping to find something similar for DBF files.

Here's a sample sub to scan all files in the folder.
Sub ScanDBFFilesInFolder(strFolder As String)
Dim s As String

If Right(strFolder, 1) <> "\" Then strFolder = strFolder & "\"

'find first dbf file
s = Dir(strFolder & "*.dbf")

Do While s > ""

Debug.Print s

'find next dbf file
s = Dir()
Loop
MsgBox "Done. All dbfs viewed"
End Sub

If you can import them, you can link to them. I assume your are doing
it by hand. That has to be a drag.
Docmd.TransferDatabase acLink, "dBase III",...

Here's an example from Help
DoCmd.TransferDatabase acImport, "Microsoft Access", _
"C:\My Documents\NWSales.mdb", acReport, "NW Sales for April", _
"Corporate Sales for April"

You might have to futz with it, try different types, but if you are
doing it manually you'll know which database type to use.

You'd then run that acLink, then the query to append, prior to the
s=Dir() line. I'd recommend you have make a copy before running and
doing testing of the mdb that has the backend tables.






"Chuck Grimsby" <cgat... (AT) gmail (DOT) com> wrote in message
news:001a8d1e-24f5-4a6e-ae9a-6883088acbb4 (AT) s9g2000yqd (DOT) googlegroups.com...
On Aug 12, 3:14 pm, "Aileen Turner" <taxiail... (AT) yahoo (DOT) com.au> wrote:

I have hundreds of dbf files to import from a folder to a table in access
2003 and or 2007. At present I import each file as a table then copy
and paste
to a master table. For other imports (text, excel etc) I have a macro
to import
all files in a folder, but I have no option to import DBF files,
Anyone able to
advise?.

Why not just link to the DBF files and run a import query against the
file? Drop the link when you're done, then move on to the next.
You can also do this for the text and excel files....


Good code Salad!

Since you can just link to the DBFs, rather then doing a Transfer, I'd
suggest just doing that, linking rather then importing. Often what I
see is that programmers import everything then run a series of queries
against the imported data to get whatever they need in the format they
need it in. A lot of work for little return. Instead, if they just
link to the data, often a query or two can do all of that in one
procedure. So rather then TransferDatabase, it's often better to link
to the data as if it were a seperate table (since it already is) via
the CreateTableDef command, and just do whatever query(s) are needed.
Faster and less repeated work for each link each time the data is
imported.

This works for Excel and CSV or TSV files as well as DBFs. Just
remember you can't do update queries on these files!
I haven't used the CreateTableDef method much so I thought it'd be as
simple as changing the connect string but it's the SourceTableName
property that needs to be changed and once it is a tabledef it doesn't
like to be changed. So I wipe out the link for each dbf that is scanned.

I'll assume the structures of all dbfs are the same. So queries could
use the table DBFFile (the name I use and created in code) for ease of
use.

So with the code to scan all the dbfs, a tabledef of the currently
scanned one can be created and then updated in whatever queries are
required pointing to tabledef "DbfFile"

Sub SetDbfSource(dbf As String)
useage: SetDbfSource "Customer.dbf"
Dim tdf As TableDef
Dim dbs As Database

Set dbs = CurrentDb

'delete existing linked file if it exists
On Error Resume Next
DoCmd.DeleteObject acTable, "DbfFile"
On Error GoTo 0

' Create a linked table
Set tdf = dbs.CreateTableDef("DbfFile")

'the connect string I use is for an old FoxPro file I have.
'the OP could create a link to one of those dbf files and then
'from the Immediate window find out what the connect string is. Ex:
'? currentdb.TableDefs("Junk").Connect will display the connect
'string

'also, the folder name C:\Test is my folder. The OP needs to be
'change itto reflect the OP's folder name
tdf.Connect = "dBase III;HDR=NO;IMEX=2;DATABASE=C:\Test"

'sets the name of the dbf
tdf.SourceTableName = dbf
dbs.TableDefs.Append tdf
dbs.close

Set tdf = Nothing
Set dbs = Nothing

End Sub

Reply With Quote
  #8  
Old   
David W. Fenton
 
Posts: n/a

Default Re: Import DBF files to Access 2003 - 08-15-2010 , 03:35 PM



Salad <salad (AT) oilandvinegar (DOT) com> wrote in
news:5oydnR22hfaAx_rRnZ2dnUVZ_t2dnZ2d (AT) earthlink (DOT) com:

Quote:
s = Dir(strFolder & "*.dbf")
It seems to me that Vista/Win7 have made it undesirable to use Dir()
for any generic functions where you don't know that the user is
going to have full access to the folder. I've found that Dir() fails
on Win7 if you try to use it on folders that are protected for
user-level security tokens (e.g., C:\). I haven't yet tried it, but
I'm assuming that the File System Object is more graceful in dealing
with this.

Am I right on this or am I missing something significant?

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.