By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,914 Members | 1,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,914 IT Pros & Developers. It's quick & easy.

Import newly created .dbf files to MS ACCESS

P: 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
Share this Question
Share on Google+
1 Reply


nico5038
Expert 2.5K+
P: 3,072
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.