Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to link to a file with an unusual name

Status
Not open for further replies.

sstump

Technical User
Oct 29, 2003
56
US
Here's the scoop. I am trying to link to all files on a network drive..my strfile looks like this "strFile = Dir(strPa * th & "FileName*.csv")". My problem is the individual files were modified after they were stored and now the end of the file names look like this "filename... .csv120706.csv" (120706 being date of the file). I can't get my code to account for this...when I remove the first .csv it works fine and creates the table.

Any suggestions how I can get this to work?
 
Yes I did...it runs fine without errors and gives me the msg box of "no files found" as I told it too if there is nothing to import. I'm still at a loss.
 
When I run this it comes back with this
"Run-time error '3011':
The Microsoft Jet database engine could not find the object 'Filename....csv1207:
Make sure the object exists and that you spelled it's name and the path name correctly"

So it's recognizing the file name per my format...and it's reading the entire file name back to me and telling me it's in correct.

Also for those that caught it I butchered the strfile above but it looks like this :

strFile = Dir(strPath & "filename*.csv")

minus the * in the middle of 'Pa' and 'th' and the path has a \ at the end.

Oh forget explaining it...here's all the code I'm using:

******
Public Function Import_From_TEXT1()
'Macro Loops through the specified directory (strPath)
'and imports Specific CSV files to specified table in the Access
'Database.

Const strPath As String = "\\networkdrive\dir1\dir2\dir3\" 'Directory Path
Dim strFile As String 'Filename
Dim strFileList() As String 'File Array
Dim intFile As Integer 'File Number


'Loop through the folder & build file list
strFile = Dir(strPath & "filename*.csv")
While strFile <> ""
'add files to the list
intFile = intFile + 1
ReDim Preserve strFileList(1 To intFile)
strFileList(intFile) = strFile
strFile = Dir()
Wend
'see if any files were found
If intFile = 0 Then
MsgBox "No files found"
Exit Function
End If

'cycle through the list of files & import to Access
For intFile = 1 To UBound(strFileList)
DoCmd.TransferText acLinkDelim, , "tblWireless", strPath & strFileList(intFile), False

Next
MsgBox UBound(strFileList) & " Files were Imported"
End Function
******

Any advice?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top