Solved

WMF picture from clipboard in Access 97?

Posted on 1997-11-15
4
542 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Works like a champ!  I can use the returned clipboard data just fine.  Thanks again.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

763 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

14 Experts available now in Live!

Get 1:1 Help Now