Link to home
Start Free TrialLog in
Avatar of mlcktmguy
mlcktmguyFlag for United States of America

asked on

Error when Adding DAO 3.5 to references

I moved a piece of code from a working Access application application into a new one.  I'm trying to compile and get and error "User defined type not defined" on the statement

Function GetFiles(strPath As String, _
                  dctDict As Dictionary, _
                  Optional blnRecursive As Boolean) As Boolean

I noticed the DAO reference wasn't present in the new module but when I try to add 'MS DAO 3.5' to the references I get an error 'Name conflicts with existing module, project or Library'.

I attached a document with a picture of the current references.  Can anyone see the conflict and tell me how to resolve it so the relocated piece of code will compile.

Here is all of the code:

Function SearchDirectory()
'
   Dim dctDict As Dictionary
   Dim varItem As Variant
   Dim GetTempDir As String
   '
   GetTempDir = SearchHere
   '
   ' 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
   '
'
DoCmd.RunMacro "Hourglass_Off"
'
   If Me.numFound = 0 Then
        MsgBox "No WMA Files Found"
   Else
        MsgBox Trim(Str(Me.numFound)) & " Files Found, " & _
        Trim(Str(Me.numDups)) & " Duplicate were Not Moved, " & _
        Trim(Str(Me.numMoved)) & " Files Moved"
   End If
   '




End Function





Function GetFiles(strPath As String, _
                  dctDict As Dictionary, _
                  Optional blnRecursive As Boolean) As Boolean
             
Dim songName As String
Dim bandName As String
Dim albumName As String
Dim trackNumber As String
Dim songNameAndBandName As String
Dim copyName As String
Dim fileExtension As String
Dim shortSongName As String
Dim songNameLength As Long
Static prevAlbumName As String
Static albumCountNum As Long
Static albumCountStr As String
'
Dim filePathAndName As String
            
   ' 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, moving any wma's to new directory.
   For Each filFile In fdrFolder.Files
        filePathAndName = filFile.Path
        '
    '    Debug.Print "before change"
    '    Debug.Print filePathAndName
    '
    '    filePathAndName = removeFunkyCharacters(filePathAndName)       ' remove single quote form string, not needed after all
    '    '
    '    Debug.Print "after  change"
    '    Debug.Print filePathAndName
    '
        
        If InStr(filePathAndName, ".wma") Then
            ' copy it
            Me.numFound = Me.numFound + 1
            'songName = Mid(filePathAndName, InStrRev(filePathAndName, "\") + 1)
            'bandName = getBandName(filePathAndName)
            'albumName = getAlbumName(filePathAndName)
            getSongBandAndAlbumName filePathAndName, _
                                    songName, _
                                    bandName, _
                                    albumName, _
                                    trackNumber
            '
            If prevAlbumName = albumName Then
            Else
                albumCountNum = albumCountNum + 1
                albumCountStr = getAlbumStr(albumCountNum)
                prevAlbumName = albumName
            End If
            
            '
            ' Increment Album Counter For Each Album
            '
            ' don't copy it if it's already there
            'Dim fileExtension As String
            'Dim shortSongName As String
            'Dim songNameLength As Long
            songNameLength = Len(Trim(songName))
            fileExtension = Mid(songName, songNameLength - 3, songNameLength)
            shortSongName = Mid(songName, 1, songNameLength - 4)
            songNameAndBandName = shortSongName & "-" & bandName & fileExtension
            '
            If Me.chkPrefixAlbumAndTrack Then
                shortSongName = albumCountStr & "_" & trackNumber & "_" & shortSongName
                songNameAndBandName = albumCountStr & "_" & trackNumber & "_" & songNameAndBandName
            End If
            ' Just songname or songname with band name attached
            '
            'copyName = songName
            '
            copyName = songNameAndBandName
            '
            If FileExists(MoveHere & copyName) Then
                Me.numDups = Me.numDups + 1
            Else
                FileCopy filePathAndName, MoveHere & copyName
                Me.numMoved = Me.numMoved + 1
            End If
            '
            DoEvents
        End If
'        If Me.numMoved > 10 Then
'            DoEvents
'        End If
   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

Open in new window

VBAReferences.doc
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

To be clear, your screenshot does not list:
    Microsoft DAO x.x Object Library

I always go with 3.5 if available.
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mlcktmguy

ASKER

Yes, I know it doesn't list it.  As I explained in my post I get an error when trying to add it.

"I noticed the DAO reference wasn't present in the new module but when I try to add 'MS DAO 3.5' to the references I get an error 'Name conflicts with existing module, project or Library'."
Thanks, Perfect