Solved

WMF picture from clipboard in Access 97?

Posted on 1997-11-15
4
554 Views
Last Modified: 2008-03-10
Hi, all.  I need to retrieve a picture from the clipboard using Access 97.  The application that puts it there actually puts it in three formats at the same time: BMP, windows metafile format, and its native format.  I want to copy the metafile version and place it in an image or frame for later use.  I'd rather not disturb the user with a dialog box every time this happens (basically every record).

I've seen the article "How to Retrieve Information from the Clipboard" -- it shows how to get text from the clipboard but I don't know how to a) go about getting a metafile format picture instead, and b) what to do with it when I've got it in order to place it in, say, an image control.

Does someone have a handy-dandy function for doing this?

Thanks in advance,
Ed


0
Comment
Question by:EdStout
[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
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
ozphil earned 200 total points
ID: 1959787
VBA does not have a Clipboard object, but VB does.
Why VB has it and VBA doesnt is beyond me.

I had a look at the C  API code to handle clipboard operations on WMF formats, and the code is as ugly as it gets. Refer to Charles Petzold 'Programming Windows'.

My workaround is to create and exe or activeX exe in VB which uses the Clipboard object to read the clipboard WMF format into a picture box, clear the clipboard and then write the picturebox back into the clipboard.

The exe form is made invisible so the user doesnt see whats happening behind the scenes.

I have coded the exe and it works fine, although i havent tried it for a multiformat clipboard image, but it should work.

I have not done an activeX exe version. With an activeX exe you could activatate the program as an object rather than shelling out to an exe.

If youre interested in this approach i could provide the VB code for you to test. There is very little code involved.


0
 

Author Comment

by:EdStout
ID: 1959788
Thanks.  I agree about the VBA omission.  And yes, if you wouldn't mind sending the code (to EdStout@Heuristech.com), it'd save some time.  And perhaps the Access code to call it, just to make sure?

Thanks again.
0
 
LVL 4

Expert Comment

by:ozphil
ID: 1959789
Thanks EdStout.

I thought id place the code here so that those paying to see the answer will actually see it. Ive hard wired the windows system and temporary directories. You can make it more generic if you wish.

1. In Access, insert the following code:

Private Sub Command2_Click()
    ' This reads the wmf image component in clipboard and replaces
    ' clipboard multiple format image with wmf format only. It also write wmf
    ' image to a temporary file c:\temp\wmfimage.wmf
    Shell ("c:\windows\readclipboardwmf.exe")
   
    ' read the temporary image file
    Image1.Picture = "c:\temp\wmfimage.wmf"
End Sub


2. In VB ( i used VB5), insert the following code:
Make a readclipboardwmf.exe from this code. Make the form visible property false.

Private Sub Form_Load()
    If Clipboard.GetFormat(vbCFMetafile) Then
        Me.Picture1 = Clipboard.GetData()
        Clipboard.Clear
        Clipboard.SetData Me.Picture1, vbCFMetafile
        ' Save image to file so that it can be read by
        ' MS Access image control
        SavePicture Picture1, "c:\temp\wmfimage.wmf"
    Else
        MsgBox "No metafile clipboard format found"
    End If

    End
 
End Sub

0
 

Author Comment

by:EdStout
ID: 1959790
Works like a champ!  I can use the returned clipboard data just fine.  Thanks again.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

752 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