By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

How do you make drag & drop possible for pictures?

P: 2
Brief introduction: I'm pretty comfortable with programming in other languages, but am 100% new to VBA and Access so I welcome all comments.

I want to be able to plug in my camera and drag a picture from the camera (DCIM folder) into a form and have access move the file to the images folder, rename it according to the names on the form, store the relative path in the form, and show the picture. I am making a directory while learning how to use access.

Right now I am doing a more basic version where I put the file in the correct 'images' location and then drag it into the hyperlink text field. The program then, "_AfterUpdate()" renames the picture according to the form. The Form (and picture) then update according to the link. My problem is that "Picture_Link_AfterUpdate()" seems to be called before a link is created in the table. Is this a good way to go about this? Is there a better way? What do you suggest? Thank you!

Here's my code:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub Picture_Link_AfterUpdate()
  4.     Dim oldPath As String, newPath As String, fileName As String
  5.     oldPath = GetFullImagePath
  6.     fileName = Me!Last & "_" & Me!First & ".jpg"
  7.     newPath = GetImagePath & fileName
  8.     If oldPath <> "" Then
  9.         Name oldPath As newPath
  10.         Me!PicturePath = "#\" & fileName
  11.     End If
  12. End Sub
  13.  
  14. Private Sub Form_Current()
  15.     Image.Picture = GetFullImagePath
  16. End Sub
  17.  
  18. Private Function GetFullImagePath() As String
  19.     Dim ImagePath As String
  20.     ImagePath = ""
  21.     If IsNull(Me!PicturePath) Then
  22.     Else
  23.         ImagePath = GetImagePath & GetFileName(Me!PicturePath)
  24.         If Len([PicturePath]) > 0 And Len(Dir(ImagePath)) > 0 Then
  25.         Else
  26.             ImagePath = ""
  27.         End If
  28.  
  29.     End If
  30.     GetFullImagePath = ImagePath
  31. End Function
  32.  
  33. Private Function GetImagePath() As String
  34.      GetImagePath = GetDBPath & "pictures\"
  35. End Function
  36.  
  37. Private Function GetDBPath() As String
  38.      GetDBPath = CurrentProject.path & "\"
  39. End Function
  40.  
  41. Private Function GetFileName(path As String) As String
  42.     Dim StartPos As Long
  43.     Dim StrLen As Long
  44.  
  45.     StartPos = InStrRev(path, "\") + 1             '+1 is to not include the slash
  46.     StrLen = InStrRev(path, "#") - StartPos        'A link will end in a #
  47.     GetFileName = Mid(path, StartPos, StrLen)
  48. End Function
  49.  
Jan 13 '14 #1

✓ answered by zmbd

Unless ADezii, TheSmileyCoder, NeoPa, or Rabbit knows better:
There's no drag and drop event in the image control.

TheSmileyCoder might have a trick with the treeview control.

You might be able to open a file dialog and be able to do the drag and drop within the dialog box, returning the folder and items logging: 32.Select a File or Folder using the FileDialog Object

Otherwise I think you are out of the normal scope.

Share this Question
Share on Google+
4 Replies


zmbd
Expert Mod 5K+
P: 5,287
Unless ADezii, TheSmileyCoder, NeoPa, or Rabbit knows better:
There's no drag and drop event in the image control.

TheSmileyCoder might have a trick with the treeview control.

You might be able to open a file dialog and be able to do the drag and drop within the dialog box, returning the folder and items logging: 32.Select a File or Folder using the FileDialog Object

Otherwise I think you are out of the normal scope.
Jan 13 '14 #2

P: 2
Thanks for the quick reply. I think I will, for the time being, just have the user place the picture in the correct location manually and then drag and drop creating a hyperlink. Maybe I will add code later to move and rename pictures, but this will work for now.

Thanks!
Jan 14 '14 #3

zmbd
Expert Mod 5K+
P: 5,287
Very well, might I suggest again that you go over the link I posted?

By opening the file dialog box, the user should be able to do the drag and drop within the dialog, select all of the files and then press OK, you can then use the code given to loop thru and pull the file locations into the database.
Jan 14 '14 #4

ADezii
Expert 5K+
P: 8,597
You can Drag-n-Drop Files from any Folder to selective Nodes of a TreeView Control using its OLEDragDrop() Event. The general idea, as well as supporting Code, would be:
  1. Have the TreeView Control active on a Form.
  2. Open Windows Explorer and select a single or multiple Files. Explorer can be opened directly from the Form itself.
    Expand|Select|Wrap|Line Numbers
    1. Dim varRetVal
    2.  
    3. varRetVal = Shell("Explorer.exe", vbNormalFocus)
    4.  
  3. Prior to the Drag-n-Drop Operation, hold down the Shift Key (not necessary - Code Line# 6)).
  4. Check the Format of the Selection to make sure that they are Files (Code Line# 7). If they are not in the desired Format, set the Effect Argument to the desired setting (Code Line# 16) and do not execute.
  5. Loop through the Selected Files (Code Lines 8-14) and add the Base File Name as Child Nodes to the Treeview ActiveX Control (Code Line# 13).
  6. Each Unique Key for each Node will be the Filename's Absolute PATH (Code Lines 12 and 13).
  7. Hope this helps.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub TreeView1_OLEDragDrop(Data As Object, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
    2. Dim nodX As Node
    3. Dim varFileName As Variant
    4. Dim strKey As String
    5.  
    6. If Shift = 1 Then       'only if Shift is held, Drag-N-Drop
    7.   If Data.GetFormat(ccCFFiles) Then
    8.     For Each varFileName In Data.Files
    9.      '1-Relative, tvwChild-Relationship, "g"-Key, "George"-Text
    10.      'The Unique Key will be the Absolute Path to the File without the Extension
    11.      'The Displayed Text will be the Absolute Path to the File with the Extension
    12.      strKey = Left$(varFileName, Len(varFileName) - 4)
    13.      Set nodX = TreeView1.Nodes.Add(1, tvwChild, strKey, varFileName)
    14.     Next
    15.   Else    'Data is not in the desired Format
    16.     Effect = ccOLEDropEffectNone
    17.   End If
    18. Else
    19. End If
    20. End Sub
Jan 14 '14 #5

Post your reply

Sign in to post your reply or Sign up for a free account.