making a file to import into Access

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Access 2003

I have a folder containing the names of image files (5432567.jpg for
instance) - sometimes 3 -5 files, other times many files. I need to create a
..txt file using just the file names from the existing folder, so that I can
import the file names into my table. Is this possible or will I need to enter
each file name into the text file by hand?

Thanks in advance
Cliffside71
 
Create the text file with the each file name on a separate line.
Link the text file like it was a table.
Write a query, SQL, or whatever to read the values in the text file and
update them to your table. But, how do you know which row to put them in?
You may need to put a key value in the text file so the query knows what rows
in your table to put them in.
 
Klatuu,

I want to create the file dynamically rather than entering each file name
into the text file by hand becaues there are sometimes up to 100 file names.

Any other suggestions?
 
Use Shell() to run a Windows DIR command and redirect its output into a
text file, e.g.

Dim strTextFileSpec As String 'textfile to create
Dim strFolder As String 'folder to get names from
Dim strCmd As String

strFileSpec = "C:\temp\file list.txt"
strFolder = Environ("UserProfile") & "\My Pictures\Pix\"
strCmd = "DIR """ & strFolder & """ /B >""" & strTextFileSpec & """"
Shell(strCmd)

One problem with Shell() is that the rest of your code doesn't wait for
the shelled process to finish. If you want to use the text file
immediately, use ShellAndWait() instead. This isn't a built-in Access
function, but there are many versions on the internet including one at
http://www.mvps.org/access.
 
Cliffside71 said:
Access 2003

I have a folder containing the names of image files (5432567.jpg for
instance) - sometimes 3 -5 files, other times many files. I need to create a
.txt file using just the file names from the existing folder, so that I can
import the file names into my table. Is this possible or will I need to enter
each file name into the text file by hand?

Thanks in advance
Cliffside71
This is Air Code.
Dim startDir As String
Dim i As Integer
Dim strFileName As String
Dim db as database
Dim rs as recordset

Set db=CurrentDb
Set rs=db.OpenRecordset("TableName")
startDir = "C:\My Folder\"
strFileName = Dir(startDir)

Do While strTemp <> ""
rs.AddNew
rs.FileAndPath = strFileName
rs.Update
strFileName = Dir
Loop

Look at the DIR command in help.

Hope this helps.

Ron
 
Back
Top