?
Solved

Read text file into variable

Posted on 2010-11-30
4
Medium Priority
?
549 Views
Last Modified: 2013-03-27
i have a text file where its contents get updated. Its has just one word in it, either Active or Inactive. Currently i have the program importing the text file into a temp table and reading it off from there. instead of iimporting to a table, can i just save it to a variable? if so, how?
0
Comment
Question by:repco
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 12

Expert Comment

by:dlan75
ID: 34242558
Hi,
you can simply read it and when it is read by Access, save it as a variable
Here are some links to help you play with text files :

http://www.databasedev.co.uk/text_files.html
http://en.allexperts.com/q/Using-MS-Access-1440/Text-Files.htm
http://www.granite.ab.ca/access/readtextfile.htm
0
 

Author Comment

by:repco
ID: 34242598
i would like an example please
0
 
LVL 7

Accepted Solution

by:
shaydie earned 1200 total points
ID: 34242829
You can use this vba code to read the first line from the text file and assign it to a variable. Paste it into a sub or function in a module or some event on a form. Change the 'FileName =' to the actual file name and path. The strVar will hold the value read from the text file.
 
nFileNum = FreeFile
FileName = "C:\PathTo\file.txt"

Open FileName For Input As nFileNum
   Line Input #nFileNum, strVar
Close nFileNum
0
 

Author Closing Comment

by:repco
ID: 34242898
Thanks!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question