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

DittoBird

New member
Local time
Today, 06:29
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:

DittoBird

New member
Local time
Today, 06:29
Joined
Nov 16, 2020
Messages
15
Thanks Moke, but I need to copy the actual image to the clipboard.
 

DittoBird

New member
Local time
Today, 06:29
Joined
Nov 16, 2020
Messages
15
Thanks Moke. This ends up copying the whole form.
 

Isaac

Lifelong Learner
Local time
Today, 01:59
Joined
Mar 14, 2017
Messages
8,777
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
 

DittoBird

New member
Local time
Today, 06:29
Joined
Nov 16, 2020
Messages
15

🙂 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: 21
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 09:59
Joined
Sep 21, 2011
Messages
14,301
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.
 

DittoBird

New member
Local time
Today, 06:29
Joined
Nov 16, 2020
Messages
15
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.
 

moke123

AWF VIP
Local time
Today, 04:59
Joined
Jan 11, 2013
Messages
3,920
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.
 

DittoBird

New member
Local time
Today, 06:29
Joined
Nov 16, 2020
Messages
15
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.
 

moke123

AWF VIP
Local time
Today, 04:59
Joined
Jan 11, 2013
Messages
3,920
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.
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:59
Joined
Sep 21, 2011
Messages
14,301
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
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:59
Joined
Sep 21, 2011
Messages
14,301
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. :)
 

isladogs

MVP / VIP
Local time
Today, 09:59
Joined
Jan 14, 2017
Messages
18,223
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
 

moke123

AWF VIP
Local time
Today, 04:59
Joined
Jan 11, 2013
Messages
3,920
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

Top Bottom