Solved

OLEDrag & Drop from the desktop

Posted on 1998-10-29
7
162 Views
Last Modified: 2010-04-30
I'm using the following function to OLEdrag and drop picture files(filenames) from the desktop or Windows Explorer into a picturebox:

Private Sub Picture1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
      Picture1.Picture = LoadPicture(Data.Files(1))
End Sub

When the file dropped isn't a valid picturebox format, I receive the Invalid Picture error. Can anyone complete my code so that any file with invalid format is rejected from being dropped?
0
Comment
Question by:slobstar
[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
  • 3
  • 3
7 Comments
 
LVL 3

Expert Comment

by:fguerreiro_inix
ID: 1442310
Use Data.GetFormat() function.

Hope this helps
Regards

0
 
LVL 1

Author Comment

by:slobstar
ID: 1442311
Thanks "fguerreiro_inix" but this was acctually the way my function really looked like:

Private Sub Picture1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
   If Data.GetFormat(15) Then
      Picture1.Picture = LoadPicture(Data.Files(1))
   End If
End Sub

It doesn't matter if I use the GetFormat function or not, if I try to drop a .txt file it will still give me an error. Maybe I use the GetFormat function incorrect, please be more specific :)
0
 
LVL 15

Expert Comment

by:ameba
ID: 1442312
You must use error handling

On error goto droperr ' enable error handling

' now your function body
    If Data.GetFormat(15) Then
      Picture1.Picture = LoadPicture(Data.Files(1))
   End If

'  now add this:
   Exit Sub

droperr:
   ' report problem and Name of your file
   msgbox error,, "Cannot load " & Data.Files(1)
   Exit sub
End Sub
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 1

Author Comment

by:slobstar
ID: 1442313
Thanks "ameba" that works, but I want the "droperr" to just reject invalid files, without displaying any error message at all.
0
 
LVL 15

Expert Comment

by:ameba
ID: 1442314
I am not sure, it is interesting problem. Hm (thinking)...
Perhaps comment out or delete line with msgbox statement.
0
 
LVL 1

Author Comment

by:slobstar
ID: 1442315
Perfectomundo!!! Just put your comment in the "answer" and the points is yours. Thanks alot /Johan
0
 
LVL 15

Accepted Solution

by:
ameba earned 50 total points
ID: 1442316
You must use error handling!

On error goto droperr ' enable error handling

' now your function body
    If Data.GetFormat(15) Then
      Picture1.Picture = LoadPicture(Data.Files(1))
   End If

'  now add this:
   Exit Sub

droperr:
   ' report problem and Name of your file
   msgbox error,, "Cannot load " & Data.Files(1)
   Exit sub
End Sub

If you don't want to report error, comment out the msgbox statement.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Script Host failed (Access is denied.) error 6 340
SLMGR Switches Are Not Working On KMS Host 3 145
Export Data to Different .csv Files 26 121
Set WorkSheet  not Working 9 52
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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 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