Solved

Read text file into variable

Posted on 2010-11-30
4
515 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now