Image Printing in Forms

Stellar0645
Stellar0645 used Ask the Experts™
on
Hello:

I have a form that includes an image - the image is tied to a key number on the form so that a different image appears as the records change. The images are not in the MDB but are stored on the hard drive with their name and location in [Image_Path].

The code to fetch the image is an Event procedure in the form properties (On current) (I don't know if this is part of the problem):

Option Compare Database
Private Sub Form_Current()
Me!Image49.Picture = [Image_Path]
End Sub

As I page through the records, the images change to match the key number, no problem.

Problem: When I Print Preview or Print, the same image is printed for every record - there is no updating during the print process.  It is the image that was last on the screen.

Any thoughts on what is causing this? I need to print these records WITH the proper image.

Thank You . . . . .
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
Mostly likely if you created an actual Report to do this ... the problem would vanish.  Printing Forms is problematic in several ways ... and this may be one of them.

mx
Adding the images to the actual database is very simple and has other advantages besides being able to print. Use an OLE Object field this link will show you how.

http://office.microsoft.com/en-us/access/HP052802251033.aspx

If this is too much work ie very large collection then there are ways to do it your way but with some troubles.
Top Expert 2016

Commented:
see if this helps

Private Sub Form_Current()
Me!Image49.Picture = [Image_Path]
me.repaint
End Sub
Acronis in Gartner 2019 MQ for datacenter backup

It is an honor to be featured in Gartner 2019 Magic Quadrant for Datacenter Backup and Recovery Solutions. Gartner’s MQ sets a high standard and earning a place on their grid is a great affirmation that Acronis is delivering on our mission to protect all data, apps, and systems.

Author

Commented:
Hello:  thank you for your responses.

Capricorn1: me.repaint had no effect, sadly.  I had great hope for such a logical fix.

csmart2301:  I'm following up on this angle, looks promising BUT, will it work when printing?

DatabaseMX:  thanks for the grim news, my last choice is to start from scratch.  Can't believe that the image behaves normally on screen but fails when printing is invoked.

Thanks, will advise on outcome, cheers . . . . . . .
100% yes it will work just add a new field as an OLE Object field. then rightclick the field/record then click insert object this is a quick print Preview from one i just built to test took less then 1 minute.
printscreen.jpg
the two records are just screen shots but this works on single form per page or multi forms per page like shown here.
You could also try a loop with the printout command
for pageFrom = 1 to recordcount
Pageto = PageFrom
FormName.PrintOut(PrintRange, PageFrom, PageTo, PrintQuality, Copies, CollateCopies)
next PageFrom

That was not actual code just an example of a way to do it the problem lies in the fact that no events are triped during a formprint so no code can run inbetween printing pages.
sending single looped print commands allows you to add code just prior to the printout command though i donot know if you will even need to at each loop the process should do what you need.


However i still suggest adding a new field as an OLE Object field.

Author

Commented:
csmart2301:

Hello  delayed on pursuing this but still going.  I've gone through this before to get the image into the form, just assumed it would print too.  Silly me!

I think the OLE option isn't too good as each image has to be pasted in separately.  I'm going to try the VBA option at the link you suggested.  Hopefully it will work.

Don't know about the PrintOut command - I'm not planning to write a printing function.

Can't believe you have to write code to enable a print function!

Thanks, will advise.  Cheers . . . . .
How many images are you talking about?
If less then say 200 then all you do is add the field to the table then to the form say next to the existing picture box run the form copy the image from the picture frame with ctrl +c right click the new ole field and select paste
Move to the next record and do it again.
Even a few thousand images could be done in a few hours.
The only problem would be data size a few thousand images would quickly make your database grow beyond the 2g limit. In which case I would make an attached database/table.

The Problem with only changing your code is no events are tripped during a form print so no code can run in between printing pages.
It does not matter how you code it the code will not run using a simple print form. unless you create a new print macro that cycles through the forms while printing them.

I agree it is stupid that you have to write code to enable a Form print function!
However workarounds are why I have a job if Microsoft wrote better easy to use programs I’d be unemployed.

Good luck
Or the other option would be to default to DatabaseMX's first post and create a report the looks just like the form. Then all the problems go away.

Author

Commented:
csmart2301:

Hello Again!

Thanks for the ideas.  I have nearly 2000 images so C&P is not an option - also they are already there.  It isn't getting them into the records, it's printing them.  As you say, data size would likely bring the whole thing to its knees anyway.

I'm following your tip in the link you provided, haven't tested it yet, other priorities have surfaced.  The only viable one looks like the VB option in: http://support.microsoft.com/default.aspx?scid=kb;en-us;285820.  But since "no events are tripped during a form print so no code can run in between printing pages", it looks like this wouldn't work anyway.  Can you advise?  In another forum, someone suggested adding the DoEvents command - does this make sense?

"I agree it is stupid that you have to write code to enable a Form print function!However workarounds are why I have a job if Microsoft wrote better easy to use programs I’d be unemployed."
Not to wish you anything but business success, but this is a shocking indictment of the rubbish produced by MS.  Is the Open Office DBMS any better?

Thanks again, will advise . . . . .

I am still going to have to suggest printing the form as a report.
so,
Just for fun try making a copy of your form and saving it as a report.
Open your Form in Design View, and click: File-->Save As
Form the "As" dropdown, select: Report.
Dose the image show up at all.


Not to wish you anything but business success, but this is a shocking indictment of the rubbish produced by MS. Is the Open Office DBMS any better?


That depends on your definition of better.
Easier to use. ok i'll give them that
as many options. No.
as a programmer i like as many options as i can cram in to a program and then some. However with each one comes new limitations and new bugs.

Make sure to convert the copy of and not the original.

Author

Commented:
csmart2301:

"Just for fun try making a copy of your form and saving it as a report."

You are likely right - the form option is certainly problematic.  This sounds hopeful, I'll try it ASAP, just bogged down on other things now.  At the very least, it might preserve most of the content and formatting.  A bit of tweaking is OK, a complete rebuild, less so.

Cheers . . . . .


Author

Commented:
csmart2301:

Just tried the "copy as . . ." form to report.  No luck.

It copies fine but just shows up in the Report section as a Form.  It still has form properties.

MS Access is a real piece of work - this is my experience when I try to do anything other than something basic.  It glitches out.
I'll try the MS VBA example but expect failure there too.

Cheers . . . . . .
thats the idea, however they are different at run time. If you look at the prop's the report should not have an Allow Datasheet View option. if it does the something went wrong if it does not then it was correctly converted.
However,
can you upload a knocked down copy of the database it will not mater that i don't have any of the images i'll take care of that on this end. just make sure that there are a few records with imagenames and all the code. this would be the quickest way to fix this i think.
Never mind the upload if the form was changed to a report then this code in the Detail_Print works in both print prevew and printed paper. The detail print will not be in the form version of the

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
     Me.Image8.Picture = Me.img
End Sub

o'corse you will have to change the field names.

Author

Commented:
csmart2301:

OK, if you're game for this.  I'll strip the DB down to the key items and send it along.  It may not be till later or tomorrow.

Thanks very much, cheers . . . . .
continued...
I hit the wrong button...
The detail print will not be in the form version of the ... Form however it will be an option on the report version of the form.

Good Luck.
Just missed you jump up 3 posts

Author

Commented:
Re:

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
     Me.Image8.Picture = Me.img
End Sub

OK, I'll try this tomorrow.  Does VBA code for Reports go in the same place as VBA for Forms?  It looks to me like all event code ends up in the same place, despite which Event it's entered under.  I find this to be very murky as to where all the moving parts are.

TU, cheers . . . . .  
yes and no each report and form have the code in modules but not the same module see the images below. to get to the vba code window for the report right click in a blank area of the detail and select build event then change the event with the pull down window to Detail_Print. see image.

Also this dose work in print and print preview but not in standerd report view. So make sure to click print and or print preview.
vba.jpg
detail.jpg

Author

Commented:
csmart2301:

Thanks very much. I appreciate your help and patience.  I should be able to get onto this shortly.

Cheers . . . .  

Author

Commented:
Hello csmart2301:

"If you look at the prop's the report should not have an Allow Datasheet View option. if it does the something went wrong if it does not then it was correctly converted."
No Allow Datasheet View, so it seems to be converted.

So I entered the code as you suggested in the Report, all code below:

Option Compare Database

Private Sub Form_Current()
Me!Image49.Picture = [Image_Path]
    Me.Repaint
    End Sub

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
End Sub

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)Me.Image49.Picture = Me.img
End Sub

Print Preview gives the following error with the bold line above highlighted in yellow:

Compile error:Method or data member not found.  OK/Help

I think it has to do with Me.img; "img" should refer to something in my database?

Thanks, cheers . . . . .
Yes
Me if the report
img was the name of my textfield that held the image location
You should use
Me!Image49.Picture = [Image_Path]

and i dont think the
Private Sub Form_Current()
Me!Image49.Picture = [Image_Path]
   Me.Repaint
   End Sub

Sub will do anything for you in report view
Sorry
Me.is the report
Also Make sure that you are placing the code in the report module not the form module like in the picture 5 post's above.
 

Author

Commented:
csmart2301:

Holy Smoke!  I made the changes (Image_path) and it worked!  I'm astounded that something so easy was made so difficult.  Bill Gates - Boo!

Anyway, I'm very grateful.  I'll assign your points shortly.

I don't really want both a Report and a Form but if I change my Form (likely) and clone it to a new Report (by the same name) will this code still be there?  I guess it would be easy enough to replicate.  My Report lacked the [Image_path] field but took off when I added it.  It is missing from the Form but I guess wasn't being referenced anyway.

I can't believe that this ONE LINE of code couldn't exist as built-in functionality.  What do they REALLY do in Redmond anyway?

Thanks again, cheers . . . . .  



DBP-report-screen.jpg

Author

Commented:
Excellent, patient help.  Persisted till the end!  Thank You!
I'm glad it worked out sorry it took so long. I should not have spent so much effort trying to get you to go ole. lol
"I don't really want both a Report and a Form but if I change my Form (likely) and clone it to a new Report (by the same name) will this code still be there? "
Sorry no.
 So when that time comes copy the code to a text file so you can paste it back in the new report.

 

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial