Solved

WMF picture from clipboard in Access 97?

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now