Solved

WMF picture from clipboard in Access 97?

Posted on 1997-11-15
4
552 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
  • 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

830 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