Solved

Access and Screen Object

Posted on 2006-06-15
15
308 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
Comment Utility
I need help on this one!
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 100 total points
Comment Utility
0
 

Author Comment

by:bin2003
Comment Utility
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
Comment Utility
Thanks
0
 
LVL 84
Comment Utility
Try CF_BITMAP
0
 

Author Comment

by:bin2003
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 58

Assisted Solution

by:harfang
harfang earned 400 total points
Comment Utility
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
Comment Utility
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
Comment Utility
I still need help on this step.

Thanks!!
0
 

Author Comment

by:bin2003
Comment Utility
How do I save it to a file??

Thanks
0
 
LVL 58

Expert Comment

by:harfang
Comment Utility
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
Comment Utility
> 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
Comment Utility
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
Comment Utility
I'm glad it worked. Success with your project!
(°v°)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
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…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

771 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

11 Experts available now in Live!

Get 1:1 Help Now