Dragging an e-mail from Outlook 98 into a Listbox

Posted on 2003-03-25
Medium Priority
Last Modified: 2008-02-01
Does anyone have any idea of how to drag an e-mail from Outlook 98, the e-mail has an msg extension, and drop the file into a Listbox?  I mean copy the whole file into a listbox, not just read the text into it.  I've been racking my brain trying to use the OLEDragDrop method of the listbox and it's driving me nuts!!
Question by:kaiserr2
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
  • 5
  • 3

Expert Comment

ID: 8206689
I'm not sure I understand: You want the "whole file into a listbox"?  But a listbox, by definition will display only a single line of text per record/row/item.

Author Comment

ID: 8206788
Im open to suggestions, doesn't have to be a listbox.  My main concern is being able to just drop the .msg into something and have the ability to double click it and open the e-mail.  The latter I can handle but it's the actual copying of the file into *some sort of control*, not necessarily a listbox, that's killing me.

Expert Comment

ID: 8206911
So, is it the DragNDrop mechanism you cannot get working?  Or is it that you get notification of the drop but cannot figure out how to get access to the message object?  Just trying to narrow the scope a little.

I have experience with Outlook and with DragNDrop so I expect I can help you here.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 8210075
The code of the OLEDragDrop event on the object I wish to drop the e-mail is the specific problem.  And for the record I have no idea how to access the message object.  Basically I've never tried programming with Outlook before and this whole thing has thrown me for a loop.

Accepted Solution

advapp earned 480 total points
ID: 8212136
Here is what I have done in the past to implement DragNDrop:

Set your target control properties as:
     OLEDropMode = [1 - ccOLEDropManual]

In the form (NOTE: my control is lstPrograms):

Private Sub lstPrograms_OLEDragDrop(data As DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, Y As Single)

    If Effect And vbDropEffectCopy Then
        Effect = vbDropEffectCopy
    End If

    If data Is Nothing Then
        'No data was passed??
    ElseIf data.GetFormat(vbCFText) Then
     GetItemText data
    ElseIf data.GetFormat(vbCFFiles) then
        AddPrograms data
    End If

    DragOverList = False

End Sub

Private Sub lstPrograms_OLEDragOver(data As DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, Y As Single, State As Integer)
    If Not DragOverList Then
        DragOverList = True
        If data.GetFormat(vbCFFiles) _
          Or data.GetFormat(vbCFText) Then
            Effect = Effect And vbDropEffectCopy
            Effect = vbDropEffectNone
        End If
    End If

End Sub

Private Sub AddPrograms(data As Object)
'Given a DataObject, iterate the collection of files,
'and add the program names to the list
Dim i As Integer

    For i = 1 To data.Files.Count
     'Get the file name and validate
        'data.Files(i) is a string containing the full pathname of each program
        'Additional massaging of the name can be done using the FSO methods
        lstPrograms.AddItem data.Files(i)

End Sub

Private Sub GetItemText(data As Object)
'Get the text

    lstPrograms.AddItem data.GetText(vbCFText)

End Sub

Expert Comment

ID: 8212167
Oops.  That entry in GetItemText should read:

lstPrograms.AddItem data.GetData(vbCFText)

What Outlook gives you in the data object is something like this:

From    Subject Received    
Bob Terzian FW: OS Request for new hire associate, Request#3438 Tue 3/25/2003 2:19 PM  

Of course, from this info, you would have to then be able to go into the Outlook object model and retrieve the actual message object.

Author Comment

ID: 8212212
Wow dude, even if this doesn't work Im going to give you the points anyways.  Thanks for the help, all I needed was a little sample code to work from.

Expert Comment

ID: 8212234
Thanks.  If you need additional help figuring out the Outlook object stuff I can assist with that.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Suggested Courses

770 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