import from text file

  • Thread starter Thread starter Shawna
  • Start date Start date
S

Shawna

I have been attempting to use vb to import information
from a text file into access (earlier posting - vb help
appreciated!) What I'm not sure of is how to I tell it
the path of where to find my text file to import? Also
how do I run the code to test how/if it's working? via
cmd button?

Thanks
Shawna
 
I think I figured out how to set the path to open my
file. And I set up a macro to run the code to test but
I'm getting an error - type mismatch Not sure why.

The macro is set to run Function

ReadALine(256)

The code is as follows:

Function ReadALine(FileNum As Long) As Variant

'read line from file, strip off quote marks
'and split into fields into an array

Dim strLine As String

Open "c:\contech\adamclark\5153.txt" For Input As
#FileNum ' Open file.

Line Input #FileNum, strLine

strLine = Replace(strLine, """", "")
ReadALine = Split(strLine, ",")

'Debug.Print strLine

Close #FileNum

End Function
 
If I change the following to

Open "c:\contech\adamclark\5153.txt" For Input As
#FileNum ' Open file.
Open "c:\contech\adamclark\5153.txt" For Input As
#1 ' Open file.

I don't get the type mismatch error anymore, but I get a
runtime # 52 error (bad file name or number)?

Sorry this post is so long.. I'm trying to do the best I
can then ask for help but I'm working as I await
response...
 
Back
Top