How Would you select a folder director Instead of a File?
What I need to do is have the path selected to the folder and Use the Dir() function to return all the contents of that folder to a field in a table
This link is to a discusion on this topic, but I figured this is more VBA related:
http://www.access-programmers.co.uk/forums/showthread.php?t=79301
Using the attached database as my reference, I was able to get it to put the file path in the text box just as the intructions said, but I want to do something similar to this but instead select the folder path and use the 'GetFiles' module or Dir() function to add all the files/ file paths to the a field in a table.
This is the code in the thread link above to get the filename into the table, but i cant get it to work .
Option Compare Database
Sub GetFiles(strPath As String)
Dim rs As Recordset
Dim strFile As String, strDate As Date
'clear out existing data
CurrentDb.Execute "Delete * From tblDirectory", dbFailOnError
'open a recordset
Set rs = CurrentDb.OpenRecordset("tblDirectory", dbOpenDynaset)
'get the first filename
strFile = Dir(strPath, vbNormal)
'Loop through the balance of files
Do
'check to see if you have a filename
If strFile = "" Then
GoTo ExitHere
End If
strDate = FileDateTime(strPath & strFile)
rs.AddNew
'to save the full path using strPath & strFile
'save only the filename
rs!FileName = strFile
rs!FileDate = strDate
rs.Update
'try for next filename
strFile = Dir()
Loop
ExitHere:
Set rs = Nothing
MsgBox ("Directory list is complete.")
End Sub
Any help?
-Thanks
What I need to do is have the path selected to the folder and Use the Dir() function to return all the contents of that folder to a field in a table
This link is to a discusion on this topic, but I figured this is more VBA related:
http://www.access-programmers.co.uk/forums/showthread.php?t=79301
Using the attached database as my reference, I was able to get it to put the file path in the text box just as the intructions said, but I want to do something similar to this but instead select the folder path and use the 'GetFiles' module or Dir() function to add all the files/ file paths to the a field in a table.
This is the code in the thread link above to get the filename into the table, but i cant get it to work .
Option Compare Database
Sub GetFiles(strPath As String)
Dim rs As Recordset
Dim strFile As String, strDate As Date
'clear out existing data
CurrentDb.Execute "Delete * From tblDirectory", dbFailOnError
'open a recordset
Set rs = CurrentDb.OpenRecordset("tblDirectory", dbOpenDynaset)
'get the first filename
strFile = Dir(strPath, vbNormal)
'Loop through the balance of files
Do
'check to see if you have a filename
If strFile = "" Then
GoTo ExitHere
End If
strDate = FileDateTime(strPath & strFile)
rs.AddNew
'to save the full path using strPath & strFile
'save only the filename
rs!FileName = strFile
rs!FileDate = strDate
rs.Update
'try for next filename
strFile = Dir()
Loop
ExitHere:
Set rs = Nothing
MsgBox ("Directory list is complete.")
End Sub
Any help?
-Thanks