Is There a Way to Copy a Linked Image to The Clipboard From a Form Linked Image Control? (1 Viewer)

DittoBird

New member
Local time
Today, 00:04
Joined
Nov 16, 2020
Messages
15
Hi folks, this concerns a form, but I imagine involves VBA or using APIs, so I've posted it here. Please let me know if there is a simpler solution.

Does anyone know if there is a way to simply directly copy an image displayed in an Access accde form like the one below? I'd prefer to use a shortcut menu (I have a whole module of VBA dedicated to creating short cut menus for many forms in my application) so my friends can just right click the image and copy it elsewhere. I can write code to copy its path, but I'd like to copy the image itself. To be able to paste the actual image onto a forum like this one or on a Word or other document.

The form uses an image control with linked picture type that the on current events sets. It's used for all parts of a hobby related application that include images, such as types of equipment, maps, photos of games, and more. The first image below shows the location of the image file, circled, relative to the location of the application. I am constantly referring to it and copy pictures by using the relative location to open the appropriate folder window and go to to open the image file in a reference subfolder co-located with the application. It would be so much easier to be able to right click or something similar on the form displaying the picture itself!

Thanks very much for any suggestions.

1702760403753.png



1702760345682.png
 
Last edited:
Thanks Moke, but I need to copy the actual image to the clipboard.
 
If this helps, there has been some extensive drag 'n drop stuff written by various UA members and 'marketed' by jack Leach, can't find it now but this may be an alternative route to what you are wanting, if not identical.

It may be an example of pushing the limits of vba a bit and was a little buggy if I remember circa 2011 correctly, but it usually worked
 

🙂 Not at all. Let me go through my process.

I first needed to convert the code from the MVP site from Private Declare Function to Private Declare PtrSafe Function in a separate module.

I then set the fImageToClipboard to the double click event:

1703189715185.png


With the following event:


Code:
Private Sub img1_DblClick(Cancel As Integer)
    On Error GoTo Err_Proc
    fImageToClipboard Me, Me.img1
Exit_Proc:
    Exit Sub
Err_Proc:
    Select Case Err.Number
        Case Else
            MsgBox "Error in " & Me.Name & ", img1_DblClick " & Err.Number & " " & Err.Description, vbCritical, "Error ", Err.HelpFile, Err.HelpContext
            Resume Exit_Proc
    End Select
End Sub

Double clicking the image control and pasting to a Word document in the very same screen shot as my initial post above gives me:

1703189951634.png


Let me just add a button as you have done instead of using a double click event - though I'm not sure why it would make a difference:

1703190408792.png


Unfortunately, I get the same result:

1703190460292.png


Any ideas what I might be doing wrong?

EDIT: It seems the code is designed for the whole form. Your example does not have a form header while mine does. Here's a couple of shots of a different picture for the same vehicle.

A screenshot of the form with a different photo:

1703191035922.png


However, what is copied to the clipboard has the wheels and tracks cut off:

1703191146406.png


So, I need to either alter the MVP code or add code to the form that makes the header invisible while fImageToClipboard executes. I'll try the later:

Code:
Private Sub btnCopy_Click()
    On Error GoTo Err_Proc
    Me.FormHeader.Visible = False
    fImageToClipboard Me, Me.img1
Exit_Proc:
    Me.FormHeader.Visible = True
    Exit Sub
Err_Proc:
    Select Case Err.Number
        Case Else
            MsgBox "Error in " & Me.Name & ", btnCopy_Click " & Err.Number & " " & Err.Description, vbCritical, "Error ", Err.HelpFile, Err.HelpContext
            Resume Exit_Proc
    End Select

That seems to work!

1703191483081.png


I have the backcolour of the image black, I should make it transparent, I guess, but that seems to accomplish what I want.
 

Attachments

  • 1703191440405.png
    1703191440405.png
    953 KB · Views: 84
Last edited:
Well I only have 32bit Access. So that is one difference.
The second is I used
Code:
Private Sub CmdCopy_Click()
Call fImageToClipboard(Me, Image0)
End Sub
as my code.
I suspect however (guess really) that you have not converted the APi's to 64 bit correctly.
I *believe* pointers like hwnd need to be changed to LongPtr as well.? It is not just a matter of PtrSafe.
 
If this helps, there has been some extensive drag 'n drop stuff written by various UA members and 'marketed' by jack Leach, can't find it now but this may be an alternative route to what you are wanting, if not identical.

It may be an example of pushing the limits of vba a bit and was a little buggy if I remember circa 2011 correctly, but it usually worked

Thanks, Isaac, but I think I've found the issue.
 
I first needed to convert the code from the MVP site from Private Declare Function to Private Declare PtrSafe Function in a separate module.
And did you also convert all the pointers and handles?


edit: Gasman beat me as I was looking at the code at Dev's site. There are about 15 Api's involved which all need to be checked for 64 bit compatibility.
 
Well I only have 32bit Access. So that is one difference.
The second is I used
Code:
Private Sub CmdCopy_Click()
Call fImageToClipboard(Me, Image0)
End Sub
as my code.
I suspect however (guess really) that you have not converted the APi's to 64 bit correctly.
I *believe* pointers like hwnd need to be changed to LongPtr as well.? It is not just a matter of PtrSafe.

I don't know much about APIs other than copying them. I've found just PtrSafe allowed the application to compile for this and other APIs. I've used. I edited my response to you earlier, I needed to make the header invisible before running fImageToClipboard because the image control size is applied to the whole form. In my edited response, you'll see how the image gets cut off if I leave the header visible.
 
I just checked a google static map app that I have which loads a png file into the edge browser control. Just tried right clicking on the image and it allows you to copy and paste into word. no code involved.
 
I just checked a google static map app that I have which loads a png file into the edge browser control. Just tried right clicking on the image and it allows you to copy and paste into word. no code involved.
Interesting, all my RC option are disabled?

1703240011358.png
 
I had no doubt it worked for you Moke.
My form is editable and not a popup,, so no idea as to why it does not do it for me, but right now, I have no need for it anyway. :)
 
I find the context menu varies depending on how the image is created
If I place the static map in a browser control, there is a right click menu including copy (though its different to that in the previous post):
1703247933878.png


Using the Copy menu works as @moke123 described.
However if I save the map as an image file and display using an image control, the entire context menu is disabled:

1703248084346.png


YMMV
 
I had no doubt it worked for you Moke.
My form is editable and not a popup,, so no idea as to why it does not do it for me, but right now, I have no need for it anyway. :)
You using a browser control? Maybe its new to the edge control.
 

Users who are viewing this thread

Back
Top Bottom