Solved

Access and Screen Object

Posted on 2006-06-15
15
309 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
  • 8
  • 4
  • 3
15 Comments
 

Author Comment

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

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 100 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
 

Author Comment

by:bin2003
ID: 16916453
Thanks
0
 
LVL 84
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 84
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
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.

 
LVL 58

Assisted Solution

by:harfang
harfang earned 400 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

911 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

22 Experts available now in Live!

Get 1:1 Help Now