By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,161 Members | 1,024 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,161 IT Pros & Developers. It's quick & easy.

Automate Import of File with Certain Text in File Name

P: n/a
Dear Access Developers:

I need to automatically import a file into Access from the same
directory every day. However, I need the code to search the files in
the directory and only import the one with the current day's date in
the file name (otherwise, the file name will not change).
Alternatively, Access could just import the one with the most recent
save date.

Can anyone provide code to do this?

Thank you.

JG Scott

Dec 21 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
G'Day,

I found this code some time ago, it grabs all the filenames in a
directory. You can use it in a standard module, and bring all the
filenames back to a variable (array - variant), and look for the one
you want.

Cheers

The Frog

Function GetAllFilesInDir(ByVal strDirPath As String) As Variant
' Loop through the directory specified in strDirPath and save each
' file name in an array, then return that array to the calling
' procedure.
' Return False if strDirPath is not a valid directory.
Dim strTempName As String
Dim varFiles() As Variant
Dim lngFileCount As Long

On Error GoTo GetAllFiles_Err

' Make sure that strDirPath ends with a "\" character.
If Right$(strDirPath, 1) <"\" Then
strDirPath = strDirPath & "\"
End If

' Make sure strDirPath is a directory.
If GetAttr(strDirPath) = vbDirectory Then
strTempName = Dir(strDirPath, vbDirectory)
Do Until Len(strTempName) = 0
' Exclude ".", "..".
If (strTempName <".") And (strTempName <"..") Then
' Make sure we do not have a sub-directory name.
If (GetAttr(strDirPath & strTempName) _
And vbDirectory) <vbDirectory Then
' Increase the size of the array
' to accommodate the found filename
' and add the filename to the array.
ReDim Preserve varFiles(lngFileCount)
varFiles(lngFileCount) = strTempName
lngFileCount = lngFileCount + 1
End If
End If
' Use the Dir function to find the next filename.
strTempName = Dir()
Loop
' Return the array of found files.
GetAllFilesInDir = varFiles
End If
GetAllFiles_End:
Exit Function
GetAllFiles_Err:
GetAllFilesInDir = False
Resume GetAllFiles_End
End Function

Dec 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.