Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:

Access and Screen Object

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
bin2003
Asked:
bin2003
  • 8
  • 4
  • 3
2 Solutions
 
bin2003Author Commented:
I need help on this one!
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
0
 
bin2003Author Commented:
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.

 
bin2003Author Commented:
Thanks
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Try CF_BITMAP
0
 
bin2003Author Commented:
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
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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
 
harfangCommented:
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
 
bin2003Author Commented:
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
 
bin2003Author Commented:
I still need help on this step.

Thanks!!
0
 
bin2003Author Commented:
How do I save it to a file??

Thanks
0
 
harfangCommented:
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
 
harfangCommented:
> 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
 
bin2003Author Commented:
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
 
harfangCommented:
I'm glad it worked. Success with your project!
(°v°)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 8
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now