Link to home
Create AccountLog in
Avatar of Lawrence Barnes
Lawrence BarnesFlag for United States of America

asked on

User-Defined Type Not Defined

Hello EE,
I need a query/function that returnes filenames, file size, file date, etc. from a folder.  I found the code referenced below on EE (http://msdn.microsoft.com/en-us/library/aa164475.aspx), but when I compile it I get a user-defined Type Not Defined error.  I'm using MSAccess 2003.  The first 3 lines are highlighted when I try to compile but I am unsure of what to check for.  Looking at references, the standard things are checked off.
* Visual Basic for Applications
* Microsoft Access 11.0 Object Library
* OLE Automation
* Microsoft DAO 3.6 Object Library
* Microsoft ActiveX Data Objects 2.1 Library.

Thank you
Function GetFiles(strPath As String, _
                dctDict As Dictionary, _
                Optional blnRecursive As Boolean) As Boolean
            
   ' This procedure returns all the files in a directory into
   ' a Dictionary object. If called recursively, it also returns
   ' all files in subfolders.
   
   Dim fsoSysObj      As FileSystemObject
   Dim fdrFolder      As Folder
   Dim fdrSubFolder   As Folder
   Dim filFile        As File
   
   ' Return new FileSystemObject.
   Set fsoSysObj = New FileSystemObject
   
   On Error Resume Next
   ' Get folder.
   Set fdrFolder = fsoSysObj.GetFolder(strPath)
   If Err <> 0 Then
      ' Incorrect path.
      GetFiles = False
      GoTo GetFiles_End
   End If
   On Error GoTo 0
   
   ' Loop through Files collection, adding to dictionary.
   For Each filFile In fdrFolder.Files
      dctDict.Add filFile.Path, filFile.Path
   Next filFile
 
   ' If Recursive flag is true, call recursively.
   If blnRecursive Then
      For Each fdrSubFolder In fdrFolder.SubFolders
         GetFiles fdrSubFolder.Path, dctDict, True
      Next fdrSubFolder
   End If
 
   ' Return True if no error occurred.
   GetFiles = True
   
GetFiles_End:
   Exit Function
End Function
You can use the following procedure to test the GetFiles procedure. This procedure creates a new Dictionary object and passes it to the GetFiles procedure.
 
Sub TestGetFiles()
   ' Call to test GetFiles function.
 
   Dim dctDict As Dictionary
   Dim varItem As Variant
   
   ' Create new dictionary.
   Set dctDict = New Dictionary
   ' Call recursively, return files into Dictionary object.
   If GetFiles(GetTempDir, dctDict, True) Then
      ' Print items in dictionary.
      For Each varItem In dctDict
         Debug.Print varItem
      Next
   End If
End Sub

Open in new window

Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

you have to add the Microsoft Scripting Runtime  to your references

also comment this line

'You can use the following procedure to test the GetFiles procedure. This procedure creates a new Dictionary object and passes it to the GetFiles procedure.
SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of Lawrence Barnes

ASKER

Thank you Capricorn1 for the answer.  Thank you Rockiroads for the insight.  I'll be sure to check it next time.