Ms-access – reading a text file in ms access

ms-access

I have a text file with some data i would like to open the text file and copy data to text box fields in form, I would like do this in event procedure for click event of a button in the same form, I am using ms access 2007.

Text file is very simple it has one column with 6 rows

12
2.5
6.7
9.5
3.4
7.6

I would like put these number to fields in the form.

Best Solution

Here's an example of how to open a text file and copy a field into a field on your form

Dim MyStr1 as string
dim MyStr2 as string

Open "TESTFILE" For Input As #1
Do While Not EOF(1)    ' Loop until end of file.
    Input #1, MyStr1, MyStr2
    me.txtStr1 = MyStr1
    me.txtStr2 = MyStr2
Loop
Close #1    ' Close file.

(the example loops through multiple rows, but you could equally well unroll the loop and do each row individually, as you might want to do - depending on how your text file is organised)

You can find more info here

Related Question