Recent Feedback
I am importing succesfully multiple named text files into Access 2003, however I need to ad a column in my access table to contain the name of each file in order for me to identify each record set. They are variable in length so the file name needs to be in each row of that files data, any help would be greatly appreciated, I am using the folowing VB and feel it just needs a slight modificationPublic Sub pfImport()On Error GoTo Err_FDim strPathFile As String, strFile As String, strPath As String, strSpec As StringDim strTable As String, ynFieldName As BooleanynFieldName = FalsestrPath = "C:\TextFiles\" 'This is where the text files are storedstrTable = "NotepadTable" 'This is my access tablestrFile = Dir(strPath & "*.txt")Do While Len(strFile) > 0strPathFile = strPath & strFileDoCmd.TransferText acImportDelim, strSpec, strTable, strPathFile, ynFieldNamestrFile = Dir()LoopExit_F:Exit SubErr_F:MsgBox Err.Number & " " & Err.DescriptionResume Exit_FEnd Sub
Optional Information: Language (or Software): Access
Hello and welcome to JustAnswer. I look forward to assisting you today with your question and providing the best answer possible.I have written the code and made a sample for youPlease let me know when you are ready and I will upload the codeThank you SuryantoSuryanto41028.1446230324
Hi Suryanto
I'm ready
Trevor
Hi Trevor,This is the code http://wikisend.com/download/387962/import1a.mdbThis is the sample text filehttp://wikisend.com/download/185656/as.txtPlease place the sample text file in C:\Textfiles and open the database filePlease open Form1 and click ImportHope this solve your problemIf you still have problem, please let me knowIf I have helped you with your issue please click the green ACCEPT button so I am compensated for my time (I am not paid until you press ACCEPT)Positive Feedback and Bonus are always appreciatedLooking forward to hearing from youThank youSuryantoRemember, if for any reason you are unsatisfied with my answer, we can continue the conversation until you’re satisfied and Accept my answer. I can address follow up questions at no extra charge and I’m always here to help. Thank you for using JustAnswer!
Looks great just one tiny problem, I import the text file into one field ie "Field1" I don't need field2, field3 or field4 how do I stop the coding asking for these fields
Thanks
Hi Trevor,That's depend on the import/export specification setup in the databaseIf you want to use in your database, please add field FNAME type TEXT in NotepadTable and you can use this codePublic Sub pfImport()On Error GoTo Err_FDim db As DAO.DatabaseDim strPathFile As String, strFile As String, strPath As String, strSpec As StringDim strTable As String, ynFieldName As BooleanynFieldName = FalsestrPath = "C:\TextFiles\" 'This is where the text files are storedstrTable = "NotepadTable" 'This is my access tablestrFile = Dir(strPath & "*.txt")Set db = CurrentDbDo While Len(strFile) > 0strPathFile = strPath & strFileDoCmd.TransferText acImportDelim, strSpec, strTable, strPathFile, ynFieldName db.Execute "UPDATE " & strTable & " SET FNAME='" & strFile & "' WHERE FNAME IS NULL"strFile = Dir()LoopMsgBox "Process Completed"Exit_F:Exit SubErr_F:MsgBox Err.Number & " " & Err.DescriptionResume Exit_FEnd Sub
Hope this helpsPlease let me know if you have problem or please click ACCEPT so I am paid for my time Positive Feedback and Bonus are greatly appreciatedPlease keep me posted
Thank you
Experience: 8 years experience in VBA(Excel, Word, Outlook and Access)