Solved

Receive File with Drop

Posted on 1998-10-20
5
145 Views
Last Modified: 2011-10-03
I want to have a form on to which the user can drag a file.  I want the drop to be an event, so that I can process the file as necessary.  How do I report the path to the file to a variable, and which event should I use to execute my code?
0
Comment
Question by:IsleOfView
5 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1440793
Set OleDropMode to Automatic.
Now you will receive an event.
0
 
LVL 5

Expert Comment

by:AnswerTheMan
ID: 1440794
Mirkwood : i've a feeling u got him all wrong.
IsleOfView: what exactly do u mean : "Dragging a file" ?
0
 

Author Comment

by:IsleOfView
ID: 1440795
I want to be able to drag a file from Windows Explorer, Desktop or whatever, get the filename into a variable, and execute code from there.  I know that the OleDrop mode will give me an event, but how do I get the filename? (i.e. "c:\testing\mytext.txt")
0
 
LVL 15

Accepted Solution

by:
ameba earned 50 total points
ID: 1440796
Set OleDropMode property of your Form to Manual.

' use its OLEDragDrop event
Private Sub Form1_OLEDragDrop(Data As DataObject, Effect ...)
    Call OLEDragDrop(Data)
End Sub

Public Sub OLEDragDrop(Data As DataObject)
    Dim i%, numfile%, filetxt$, filnam As String
    If Data.GetFormat(vbCFFiles) Then
        On Error GoTo NEXTFILE
        For i = 1 To Data.Files.Count
            filnam = CStr(Data.Files.Item(i))
            numfile% = FreeFile
            Open filnam For Input As #numfile%
            'read file and do something, e.g. show first line
            Line Input #numfile%, filetxt$
            MsgBox filnam & vbCrLf & filetxt$
            Close numfile%
NEXTFILE:
        Next
    End If
End Sub
0
 

Author Comment

by:IsleOfView
ID: 1440797
Thank you...that worked perfectly.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

756 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