Solved

Read text file into variable

Posted on 2010-11-30
4
508 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
  • 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 300 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now