?
Solved

Drag and drop folders to determine contents

Posted on 2005-04-28
3
Medium Priority
?
147 Views
Last Modified: 2012-05-05
I thought I had this working until I tried to grab the My Documents folder onto my form.  When doing so, I get the following error:

Specified format does not match format of data.

Any other folder I've dragged onto the form has successfully listed the contents in my list box.  Is there something special I have to do to get folders like My DOcuments to work?

Below is my code:

Private Sub Form_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, Y As Single)
On Error GoTo Error:
    Dim fso As FileSystemObject
   
    List1.Clear
    Set fso = New FileSystemObject
    GetFiles fso.GetFolder(Data.Files(1))
    Set fso = Nothing
   
    Exit Sub
Error:
    Set fso = Nothing
    MsgBox "Not a valid folder.", vbOKOnly Or vbExclamation, "Error"
End Sub

Private Sub GetFiles(Folder)
    Dim SubFolders
    Dim SubFolder
    Dim Files As Files
    Dim File As File
   
    Set Files = Folder.Files
    If Files.Count <> 0 Then
        For Each File In Files
            List1.AddItem File.Name
        Next
    End If
   
    Set SubFolders = Folder.SubFolders
    If SubFolders.Count <> 0 Then
        For Each SubFolder In SubFolders
            GetFiles SubFolder
        Next
    End If
End Sub
0
Comment
Question by:Metallicraft
  • 2
3 Comments
 

Author Comment

by:Metallicraft
ID: 13884810
Let me add...

I'm dragging from Windows Explorer.  And what I'm dragging is the My Documents in the file list directly under Desktop.  If, instead, I go to c:\documents and settings\<username>, I can drag THAT My Documents successfully onto my form.  
0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 150 total points
ID: 13885222
I don't think that will work because "My Documents" on your desktop is not an actual folder.You could try getting the location of the folder and passing it to your GetFiles sub.

    Dim Wshell As Object, Fold
    Set Wshell = CreateObject("WScript.Shell")
    Fold = Wshell.SpecialFolders("MyDocuments")

    Set fso = New FileSystemObject
    GetFiles fso.GetFolder(Fold)
    Set fso = Nothing
    Set Wshell = Nothing

0
 

Author Comment

by:Metallicraft
ID: 13885436
That works well.  Is there a way to tell if what's being dragged onto the for is the My Documents folder so I know what to do in that situation?
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month15 days, 16 hours left to enroll

850 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