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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compile Error - user-defined type not defined (FileSystemObject) 1

Status
Not open for further replies.

tubbers

Technical User
Jun 23, 2004
198
US
Hi,

I'm using the following code to look through folders/subfolders and create a table using the file names and paths. I get the error "Compile error: User-defined type not defined".

Code:
Option Explicit

Public Function AppendFileList(strFolder As String, IncludeSubFolders As Boolean)
On Error GoTo errHandler

Dim objFSO As FileSystemObject
Dim objFolder As Folder
Dim objFiles As File
Dim strFileNames As String
Dim strSubFolder As Folder

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strFolder)

For Each objFields In objFolder.Files
DoCmd.SetWarnings False
strCount = strCount + 1
DoCmd.RunSQL ("Insert Into TblFileList Values('" & objFiles.Name & "','" & objFolder.Path & "';")
DoCmd.SetWarnings True
DoEvents
strFilesFound = strFilesFound & vbCrLf & objFiles.Name

Next

If IncludeSubFolders = True Then
For Each strSubFolder In objFolder.SubFolders
Call AppendFileList(strSubFolder.Path, True)
Next
End If

I had the MS DAO 3.6 Object Library checked in references along with VB for Applications, Access Object Library and OLE Automation.

I'm running this from the Immediate Window using
Code:
?appendfilelist ("c:\3d\final\tat", "False")

Can anyone offer any suggestions on what needs to be fixed?
 
You must set a reference to the "Microsoft Scripting Runtime" in order for the FileSystemObject to work.


Rob
 
Well, that was an easy one. Thanks, Rob.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top