M
mccallen60
Good morning,
Thanks in advance for reading this. I am a VB newbie. I found this code
online that allows me to import multiple txt files (with different names)
into a table in my Access 2003 database table. It works like a charm.
However, I want to modify this code to have it prompt me for the file
location of the txt files to import, then prompt me again to where I want to
send the txt files to archive. The code is as follows:
'This sub will import all text files @ C:\Import TXT files\ and
'move them to the C:\Archived TXT Files\ folder. This example imports
'delimited text files with the import specification named TextImportSpecs
'and the imported files do not have field names.
Public Function bImportFiles_Click()
On Error GoTo bImportFiles_Click_Err
Dim objFS As Object, objFolder As Object
Dim objFiles As Object, objF1 As Object
Dim strFolderPath As String
strFolderPath = "h:\Lunch & Learn Activities\FY 2008-09\2009-03\"
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(strFolderPath)
Set objFiles = objFolder.files
For Each objF1 In objFiles
If Right(objF1.Name, 3) = "txt" Then
DoCmd.TransferText acImportDelim, "Log Import Specification", "Combined
Logs", strFolderPath & objF1.Name, False
Name strFolderPath & objF1.Name As "h:\Lunch & Learn Activities\FY
2008-09\2009-03\Imported\" & objF1.Name 'Move the files to the archive folder
End If
Next
Set objF1 = Nothing
Set objFiles = Nothing
Set objFolder = Nothing
Set objFS = Nothing
bImportFiles_Click_Exit:
Exit Function
bImportFiles_Click_Err:
MsgBox Err.Number & " " & Err.Description
Resume bImportFiles_Click_Exit
End Function
Any help is greatly appreciated. Thanks again. Kevin
Thanks in advance for reading this. I am a VB newbie. I found this code
online that allows me to import multiple txt files (with different names)
into a table in my Access 2003 database table. It works like a charm.
However, I want to modify this code to have it prompt me for the file
location of the txt files to import, then prompt me again to where I want to
send the txt files to archive. The code is as follows:
'This sub will import all text files @ C:\Import TXT files\ and
'move them to the C:\Archived TXT Files\ folder. This example imports
'delimited text files with the import specification named TextImportSpecs
'and the imported files do not have field names.
Public Function bImportFiles_Click()
On Error GoTo bImportFiles_Click_Err
Dim objFS As Object, objFolder As Object
Dim objFiles As Object, objF1 As Object
Dim strFolderPath As String
strFolderPath = "h:\Lunch & Learn Activities\FY 2008-09\2009-03\"
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(strFolderPath)
Set objFiles = objFolder.files
For Each objF1 In objFiles
If Right(objF1.Name, 3) = "txt" Then
DoCmd.TransferText acImportDelim, "Log Import Specification", "Combined
Logs", strFolderPath & objF1.Name, False
Name strFolderPath & objF1.Name As "h:\Lunch & Learn Activities\FY
2008-09\2009-03\Imported\" & objF1.Name 'Move the files to the archive folder
End If
Next
Set objF1 = Nothing
Set objFiles = Nothing
Set objFolder = Nothing
Set objFS = Nothing
bImportFiles_Click_Exit:
Exit Function
bImportFiles_Click_Err:
MsgBox Err.Number & " " & Err.Description
Resume bImportFiles_Click_Exit
End Function
Any help is greatly appreciated. Thanks again. Kevin