Login|Contact Us
Question and Answer

Programming

Ask a Programming Question, Get an Answer ASAP!

  • Ask A Question
  • Browse Answers
  • Meet The Experts
  • How JustAnswer Works

I am importing succesfully multiple named text files into Access

 
Suryanto's Avatar
  • Answered by:Suryanto
  • Programmer
  • Positive Feedback: 100.0 %
  • Accepted Answers: 505
Verified Expert
in Programming

Recent Feedback

Positive
VERY HELPFULL
Positive
Suryanto has provided answers to many of my tough VBA issues. He is truly an...
Positive
THanks!!!
Positive
Expert provided good answer and was quick
Positive
Excellent well done I now know where to come for future problems
Positive
Prompt and easy. Thanks for putting in the sample MDB!
Positive
thanks a lot
Positive
You do good work ! Thanks!
Positive
Thank you so much for your help. What you sent me was exactly what I was after....

Customer Question

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 modification

Public Sub pfImport()
On Error GoTo Err_F

Dim strPathFile As String, strFile As String, strPath As String, strSpec As String
Dim strTable As String, ynFieldName As Boolean
ynFieldName = False
strPath = "C:\TextFiles\" 'This is where the text files are stored
strTable = "NotepadTable" 'This is my access table
strFile = Dir(strPath & "*.txt")
Do While Len(strFile) > 0
strPathFile = strPath & strFile
DoCmd.TransferText acImportDelim, strSpec, strTable, strPathFile, ynFieldName

strFile = Dir()
Loop
Exit_F:
Exit Sub

Err_F:
MsgBox Err.Number & " " & Err.Description
Resume Exit_F

End Sub

 

Optional Information:
Language (or Software): Access

Submitted: 342 days and 5 hours ago.
Category: Programming
Value: £43
Status: CLOSED
Picture
Expert:  Suryanto replied 341 days and 19 hours ago.

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 you

Please let me know when you are ready and I will upload the code


Thank you
SuryantoSuryanto41028.1446230324

Customer replied 341 days and 10 hours ago.

Hi Suryanto

I'm ready

Trevor

Picture
Expert:  Suryanto replied 341 days and 10 hours ago.

Hi Trevor,

This is the code
http://wikisend.com/download/387962/import1a.mdb

This is the sample text file
http://wikisend.com/download/185656/as.txt

Please place the sample text file in C:\Textfiles and open the database file
Please open Form1 and click Import

Hope this solve your problem

If you still have problem, please let me know

If 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 appreciated

Looking forward to hearing from you

Thank you
Suryanto


Remember, 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!

Customer replied 341 days and 9 hours ago.

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

Accepted Answer

Picture
Expert:  Suryanto replied 341 days and 9 hours ago.

Hi Trevor,

That's depend on the import/export specification setup in the database

If you want to use in your database, please add field FNAME type TEXT in NotepadTable and you can use this code

Public Sub pfImport()
On Error GoTo Err_F

Dim db As DAO.Database

Dim strPathFile As String, strFile As String, strPath As String, strSpec As String
Dim strTable As String, ynFieldName As Boolean

ynFieldName = False
strPath = "C:\TextFiles\" 'This is where the text files are stored
strTable = "NotepadTable" 'This is my access table
strFile = Dir(strPath & "*.txt")

Set db = CurrentDb

Do While Len(strFile) > 0

strPathFile = strPath & strFile
DoCmd.TransferText acImportDelim, strSpec, strTable, strPathFile, ynFieldName
db.Execute "UPDATE " & strTable & " SET FNAME='" & strFile & "' WHERE FNAME IS NULL"

strFile = Dir()
Loop

MsgBox "Process Completed"

Exit_F:
Exit Sub

Err_F:
MsgBox Err.Number & " " & Err.Description
Resume Exit_F

End Sub

 

Hope this helps

Please let me know if you have problem or please click ACCEPT so I am paid for my time
Positive Feedback and Bonus are greatly appreciated

Please keep me posted

 

Thank you

Suryanto

Remember, 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!Suryanto41028.3715799769

Expert TypeProgrammer
Category: Programming
Pos. Feedback: 100.0 %
Accepts: 505
Answered: 4/29/2012

Experience: 8 years experience in VBA(Excel, Word, Outlook and Access)

Ask this Expert a Question >
 
Tweet

6 Programmers are Online Right Now

Ask Your Question Now
Programming Questions Date Submitted
is there a python programming person available 3/28/2013
Write a menu-driven program that allows users do two options: Option 3/27/2013
1. Which one of the following control structures provides for 3/27/2013
JavaScript: Multiple Choice Questionnaire 3/25/2013
RA-211 3/24/2013
How do you create a searchable public Google drive folder in 3/24/2013
RA-211 3/24/2013
I am an entrepreneur with no current coding skills, but an 3/23/2013
I have base code in VBA that opens all excel files from a folder 3/23/2013
Program in C++ 3/23/2013
RSS
Next 10 >
Ask A Programmer
Type Your Programming Question Here...
characters left:

Top Programming Experts

See More Programmers

In The News

Nbc
Washington Post
New York Times
Cnn
Learn More

How It Works

  • Ask an Expert
  • Get a Professional Answer
  • Ask Followup Questions
  • 100% Satisfaction Guarantee
Learn More
close
Find Expert answers related to your question.
Sign up using email
We will never post anything without your permission.
Already have an account? Sign in

Ask a Programmer

Get a Professional Answer. 100% Satisfaction Guaranteed.
183 Programmers are Online Now
Type Your Programming Question Here...
characters left:
Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.
Truste
Contact Us | Terms of Service | Privacy & Security | About Us
© 2003-2013 JustAnswer LLC