Solved

User-Defined Type Not Defined

Posted on 2009-05-05
4
622 Views
Last Modified: 2013-11-27
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

0
Comment
Question by:Lawrence Barnes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 24309225
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.
0
 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 50 total points
ID: 24309257
Cap has given you the answer but if you note in your link, on the left hand side, select the option above "Returning Files from the File System". When following articles from ms, you gotta start from the first page. The first page states

By default, no reference is set to this library, so you must set a reference before you can use it. If Microsoft Scripting Runtime does not appear in the References dialog box (Tools menu), you should be able to find it in the C:\Windows\System subfolder as Scrrun.dll
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 450 total points
ID: 24309278
also on the test procedure

Sub TestGetFiles()
   ' Call to test GetFiles function.
 
   Dim dctDict As Dictionary
   Dim varItem As Variant

'add these
dim GetTempDir as string
GetTempDir="c:\myFolder"   ' change accordingly the path  


   ' 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
0
 
LVL 5

Author Closing Comment

by:Lawrence Barnes
ID: 31578226
Thank you Capricorn1 for the answer.  Thank you Rockiroads for the insight.  I'll be sure to check it next time.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MS Access / SQL Server - ODBC Problems 16 57
How to get data off Lotus Notes server 4 69
Outlook Automation in Access Using "Find" 2 57
Combo box question 6 54
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question