468,170 Members | 1,811 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,170 developers. It's quick & easy.

Import newly created .dbf files to MS ACCESS

31
I am trying to import .dbf files to ACCESS. The files all start with "QB" and then Numbers ie.. QB0001, QB0002. I am getting the files in but the code I have changes the name to the first file in the dir and increments all others from that file name. I am new to the coding game and need help on this one.

Expand|Select|Wrap|Line Numbers
  1. Private Sub_Import() 
  2.   Dim strPath As String 
  3.   Dim strTableName As String 
  4.   Dim strFileName As String 
  5.   Dim dbs As Database 
  6.  
  7.   Set dbs = CurrentDb 
  8.   strPath = "C:\NEWFOLDER\" 
  9.    strTableName = Dir(strPath) . 
  10.    strFileName = Dir(strPath & QB*.dbf") ' Retrieve the first entry file name. 
  11.      Do While strFileName <> "" ' Start the loop. 
  12.      DoCmd.TransferDatabase acImport, "dBase IV", strPath,, strFileName, 
  13. strTableName, False 
  14.    strFileName = Dir  
  15.    Loop 
  16. End Sub
Sep 20 '07 #1
1 1898
nico5038
3,079 Expert 2GB
I am trying to import .dbf files to ACCESS. The files all start with "QB" and then Numbers ie.. QB0001, QB0002. I am getting the files in but the code I have changes the name to the first file in the dir and increments all others from that file name. I am new to the coding game and need help on this one.

Expand|Select|Wrap|Line Numbers
  1. Private Sub_Import() 
  2.   Dim strPath As String 
  3.   Dim strTableName As String 
  4.   Dim strFileName As String 
  5.   Dim dbs As Database 
  6.  
  7.   Set dbs = CurrentDb 
  8.   strPath = "C:\NEWFOLDER\" 
  9.    strTableName = Dir(strPath) . 
  10.    strFileName = Dir(strPath & "QB*.dbf") ' Retrieve the first entry file name. 
  11.      Do While strFileName <> "" ' Start the loop. 
  12.      DoCmd.TransferDatabase acImport, "dBase IV", strPath,, strFileName, 
  13. strTableName, False 
  14.    strFileName = Dir  
  15.    Loop 
  16. End Sub
Not sure what your objective is. Besides a missing " before the QB*.dbf", all code look OK to me.
When you want each QB file to be stored into a different table, then use the strFilename (without .dbf) also for the tablename in the Docmd:
Expand|Select|Wrap|Line Numbers
  1.    strFileName = Dir(strPath & QB*.dbf") ' Retrieve the first entry file name. 
  2.      Do While strFileName <> "" ' Start the loop.  
  3.      DoCmd.TransferDatabase acImport, "dBase IV", strPath,, strFileName, 
  4. Replace(strFileName,".dbf",""), False 
  5.    strFileName = Dir  
  6.    Loop 
  7. End Sub
Nic;o)
Oct 5 '07 #2

Post your reply

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

Similar topics

3 posts views Thread by *no spam* | last post: by
1 post views Thread by David Berry | last post: by
4 posts views Thread by db2admin | last post: by
1 post views Thread by gcdp | last post: by
reply views Thread by gcreed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.