FileOpenDialog for text file import

  • Thread starter Thread starter Kurokaze204
  • Start date Start date
K

Kurokaze204

Hi,
I'm fairly new. Want to import text files into database
via VBA. Two questions:
1) How do I call a FileOpen Dialog Box like Windows
File...Open to find the file and return Path\filename

2) What commands should I use to open, read the file one
line at a time and close the csv file?

Thanks.
 
To recreate the Windows FileOpen dialog box, there is code at:

http://www.mvps.org/access/api/api0001.htm

To open and read that file, you will use something like this:

Dim intHandle As Integer
Dim strTextLine As String

intHandle = FreeFile()
Open "c:\myfile.txt" For Input As #intHandle ' Open file.
Do While Not EOF(intHandle)
Line Input #intHandle, strTextLine
' Your code here to read selected bytes from each line of the text file
Loop
Close #intHandle


For further information, use VBA Help on the Open Statement

hth,
 
Back
Top