Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access and Screen Object

Posted on 2006-06-15
15
Medium Priority
?
318 Views
Last Modified: 2012-06-27
I want to include screen shot of active form in a sub report in Access. How can I automate this using VBA? I can manually do this using PrintScreen, but I want to do it with vba. Any suggestions?
0
Comment
Question by:bin2003
[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
  • 8
  • 4
  • 3
15 Comments
 

Author Comment

by:bin2003
ID: 16915858
I need help on this one!
0
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 400 total points
ID: 16915873
0
 

Author Comment

by:bin2003
ID: 16916421
LSMConsulting

Very good! Using this code I can copy screen to clipboard. But I am still having problems retrieving from the clipboard. The statement Me.Image1 = Clipboard.GetData(vbCFBitmap) gives me a compile error "Variable not defined"

Thanks again!!!!
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

Author Comment

by:bin2003
ID: 16916453
Thanks
0
 
LVL 85
ID: 16916463
Try CF_BITMAP
0
 

Author Comment

by:bin2003
ID: 16921862
Progress!!

However in the statement "Me.Image1.Picture = GetClipboardData(CF_BITMAP)" I get the error "MS Office can't open the File '0'. Seems like .Picture requires file name.

Help.

Thanks Again - we're getting there.
0
 
LVL 85
ID: 16922451
The Image control will require a full path to your image ... try saving the image to a file and pointing the Image control to that file. You could save this to a temp file and then delete as needed ...
0
 
LVL 58

Assisted Solution

by:harfang
harfang earned 1600 total points
ID: 16922510
Hello bin2003

To write into an image, you need the PictureData property, not Picture (which expects a file name). However, I'm not sure at all that the clipboard's picture format is compatible with the Access PictureData property of image controls...

You could also select an unbound object frame and use "RunCommand acCmdPaste". This would enable all the normal conversion operations that occure during copy-paste operations.

Good luck!
(°v°)
0
 

Author Comment

by:bin2003
ID: 16930664
Still having problems saving to file.

I can copy screen to clipboard. I can save an image to a file.

How do I get image from clipboard to image?

GetClipboardData(CF_BITMAP) seems to return a Long value that is the handle of the image. How do I get the image????

Thanks for ALL HELP!!

0
 

Author Comment

by:bin2003
ID: 16935306
I still need help on this step.

Thanks!!
0
 

Author Comment

by:bin2003
ID: 16938713
How do I save it to a file??

Thanks
0
 
LVL 58

Expert Comment

by:harfang
ID: 16938764
bin2003

I played around a little bit with these bitmaps, but it's really too hard using VB. Unless you are a true guru like Stephen Lebans, who would be able to pull this off. See for example:
http://www.lebans.com/windowtobitmap.htm

The return value of GetClipboardData is of course a long pointer to the bitmap image in memory. You could get that, transform it into a string and feed that to a .PictureData property. Unluckily, this is all very hard to accomplish in VB (probably a single line of code in C)...

I tried this for you:
 • create a table "zstblSnapshot" with a single ole field "Bitmap"
 • insert a single record, prefilled with a simple bitmap.
 • create a form with some stuff and a button cmdSmile (to take the picture)
 • use zstblSnapshot as Record source, with AllowDeletions:No and AllowAdditions:No
 • drag Bitmap to the form, rename to bofBitmap and make invisible
 • create a report showing zstblSnapshot.Bitmap, and nothing else: rptSnapshot
 • use this event for cmdSmile:

Private Sub cmdSmile_Click()
    ScreenDump Me.Hwnd
    bofBitmap.Visible = True
    bofBitmap.SetFocus
    RunCommand acCmdPaste
    RunCommand acCmdSaveRecord
    cmdSmile.SetFocus
    bofBitmap.Visible = False
    DoCmd.OpenReport "rptSnapshot", acViewPreview
End Sub

ScreenDump is the function from MS that LSMC was kind enough to provide. The only change I made to it was to accept a window handle so that it would print only the form, not the entire Access window.

Anyway, this works to specifications: take a snapshot of a form and show it in a report. You can use the report as subreport if needed, naturally. Likewise, you can paste into zstblSnapshot.Bitmap in a separate form, in a subform, etc. so as not to disrupt your current GUI.

Cheers!

(°v°)
0
 
LVL 58

Expert Comment

by:harfang
ID: 16938775
> How do I save it to a file??
Study S.Lebans' code long enough, and you might find the way to do that. I didn't and haven't...
This is really quite hard without a good manual at hand and without a true system oriented programming language, no?

(°v°)
0
 

Author Comment

by:bin2003
ID: 16956195
Thank You - harfang and LSMConsulting!!!

Works great - I sure wish I had more points (apparently 500 is max).

You saved me, I never could have comleted this without your help.

Thanks again.
0
 
LVL 58

Expert Comment

by:harfang
ID: 16956467
I'm glad it worked. Success with your project!
(°v°)
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

722 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