FileOpenDialog for text file import

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.
 
C

Cheryl Fischer

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top