I am importing 20 lists from a folder, into a table called "ELDO_COMBINED" in access. I am also creating a field called "list" in "ELDO_COMBINED" that i need to populate with the name of the file that particular record was imported from.
here's my code so far, its almost done but this last step has me stumped
The Code in red is where i am stuck, please help!Code:Private Sub ACS_START_Click() 'ZIP SCRIPT Dim ArchiveFolderPath As String Dim orgLocation As String Dim strSourceFile As String Dim OldFilePath As String Dim NewFilePath As String Dim InVoicePath As String Dim objFS As Object, objFolder As Object Dim objF1 As Object Dim strFolderPath As String Dim deleteSQLquery As String Dim i As Integer Dim CurrDate As String Dim zipfiles As String Dim retVAL As String Dim password As String Dim InVoice As String Dim ArchiveInvoice As String Dim FSO As Object Dim oApp As Object Dim Fname As Variant Dim FileNameFolder As Variant Dim DefPath As String Dim strDate As String Dim need As String Dim fiELDName As String Dim YAYnay As Boolean 'TEXT FILE SCRIPT Dim objFS2 As Object, objFolder2 As Object Dim objF12 As Object Dim orgLocation2 As String Dim ArchiveFolderPath2 As String Dim OldFilePath2 As String Dim NewFilePath2 As String Dim ListFill As String CurrDate = Month(Date) & "-" & Day(Date) & "-" & Year(Date) orgLocation = "C:\WORK\ELDO\START\" orgLocation2 = "C:\WORK\ELDO\" DoCmd.SetWarnings False DoCmd.RunSQL "DELETE * from ELDO_COMBINED" DoCmd.SetWarnings True need = "ELDO_COMBINED" fiELDName = "LIST" YAYnay = False Find_Field need, fiELDName, YAYnay If YAYnay = False Then DoCmd.RunSQL "ALTER TABLE ELDO_COMBINED ADD COLUMN LIST VARCHAR (45);" End If 'string will be this folder ArchiveFolderPath = orgLocation ArchiveFolderPath2 = orgLocation2 OldFilePath = "C:\WORK\ELDO\START\" NewFilePath = "C:\WORK\ELDO\IMPORTED\" Start = orgLocation 'opens workbook Set objFS = CreateObject("Scripting.FileSystemObject") 'folder is now accessable Set objFolder = objFS.getfolder(ArchiveFolderPath) 'ready to import files Set objFiles = objFolder.files For Each objF1 In objFiles 'If Right(NewName, 3) = "csv" Then If Right(objF1.Name, 3) = "CSV" Then DoCmd.TransferText acImportDelim, "ImportSpec", "ELDO_COMBINED", orgLocation & objF1.Name, False ELDO_COMBINED.list = objF1.Name End If Next 'DoCmd.TransferText acImportDelim Set objF1 = Nothing Set objFiles = Nothing Set objFolder = Nothing Set objFS = Nothing Dim sEcfEEd As Long Dim intro As New ADODB.Recordset Dim tblpass As String tblpass = "select*from ELDO_COMBINED" fEEd = fEEd + 1 intro.Open tblpass, CurrentProject.Connection, adOpenStatic 'intro.Open Ssql, CurrentProject.Connection, adOpenStatic With intro sEcfEEd = .RecordCount End With intro.Close 'opens workbook Set objFS = CreateObject("Scripting.FileSystemObject") 'folder is now accessable Set objFolder = objFS.getfolder(ArchiveFolderPath) 'ready to import files Set objFiles = objFolder.files 'Transfers imported files into IMPORTED folder.................................. For Each objF1 In objFiles If Right(objF1.Name, 3) = "CSV" Then OldFilePath = "C:\WORK\ELDO\START\" & objF1.Name ' original file location NewFilePath = "C:\WORK\ELDO\IMPORTED\" & objF1.Name ' new file location Name OldFilePath As NewFilePath ' move the file End If Next Set objF1 = Nothing Set objFiles = Nothing Set objFolder = Nothing Set objFS = Nothing 'End If bImportFiles_Click_Exit: Exit Sub bImportFiles_Click_Err: MsgBox Err.Number & " " & Err.Description Resume bImportFiles_Click_Exit End Sub
Thank you![]()



Reply With Quote