printing pic from access by vba

U

ulrich1947

Hi everybody,

I have made a program listing names of pics and applicable keywords. this
works fine. the pics are shown in my form by a command e. g.
"BildObj0.Picture = C:\Archiv\P\P00005.jpg". So far everything is ok. Now I
want to print out this pic by using visual basic (via an
doubleClick-procedure on a command button). Is there anything else (and more
simple) than a Shell Command and - if not - how is such a Shell Command
properly written ?

Maybe anyone can help

Thanks a lot

Ulrich
 
A

Albert D. Kallal

If you can "right click on a picture and choose print, then the following
line of code should print the picture:

CreateObject("Shell.Application").Namespace(0).ParseName("c:\mypdf\myDoc.pdf").InvokeVerb
("&Print")

The above would print a pdf document, but it also works for word, excel
etc.....

So, whatever is your default picture printer will be launched when you run
the above....
 
U

ulrich1947

Thank you for trying to help me. Unfortunately the given command does not
work. Furthermore, the pic's i want to be printed are not seen at all in my
form - so i can't right click them. the form just lists the path, where the
..jpg file can be found - and some more related information to the pic - but
not the pic itself.

is there any other way ? Thanks again.

Ulrich
 
J

JimBurke via AccessMonster.com

I think that you could create a report with an image file control on it. In
the report's Open event proc, use the VBA command:

Me.Controls("imgControl").Picture = "fileName"

Where 'imgControl' is the name of the image control and 'fileName' is the
fully qualified file name of the picture file. Try that out.
 
J

Jack Leach

Look up the ShellExecute API (one can be found at mvps.opg/access in the APIs
section), and replace the second argument with "print" instead of
vbNullString.

This seems to be the equivelent of right-clicking a file and clicking Print
from the subsequent dropdown.

So far it works on everything I've tried it on, but I haven't tried it on a
pic of any sort. I would imagine that, if this does work in this case, you
would get the standard windows wizard for printing an image (size/layout
copies, etc)

hth - let me know if you need any more details to try it
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
U

ulrich1947

Thanks All for contributing.

To Jack Leach:
I've thougth about using a report before but actually didn't want to use an
extra report. However I used your method and it works fine. In any case, your
way is much shorter than a one I would have made on my own. Thanks.

To Jim Burke:
Thanks for your advice. But for my stage of knowledge it seems a bit too
complicated. But I am sure, your way works too and as I am nosy by birth, I
will try your way soon, just to widen my experience.

My regards

Ulrich
 
J

JimBurke via AccessMonster.com

Nothing complicated about my solution, pretty simple actually, but if Jack's
works then you're all set. His is a bit simpler and doesn't involve any new
objects or controls.

If you did want to test mine out just to get the experience, this is
everything you'd have to do:

1) create a new report
2) drag an Image control onto the report from the Toolbox. when it prompts
you for the image file you can just select any picture file you have out
there - you'll be overriding it anyway.
3) create an Open event procedure for the report and put in the statement I
showed earlier. I'm assuming you have a way of specifying the file name on a
form already. You would just set the Picture property equal to that file name.

4) On the form where the picture will be printed from, create a button
control that opens the report. Before opening the report, make sure the user
has selected a file name.

That's it. Not much to it.
 
A

Albert D. Kallal

ulrich1947 said:
Thank you for trying to help me. Unfortunately the given command does not
work. Furthermore, the pic's i want to be printed are not seen at all in
my
form - so i can't right click them.

Correct, I was not suggesting that you right click them, I'm suggesting that
if you **can** right click them in the windows explore, them my example code
posted a likely work.


in other words if you right click a word document in the windows explorer,
there's a print option that displays.

in other words if you right click in excel document in the windows explorer,
there's a print option that displays

in other words if you're right click a pdf document in the windows explorer,
there's a print option that displays.

So the logical suggestion from above is to right click on any pictures in
the windows explorer, and do you get a print option?

I have some pitcher editing software installed in my computer, and therefore
I do have what's called a right click context menu that allows me to print
pictures.

however this does assuming mean that you have to have the appropriate
software installed in your computer.

My example code will work for word printing if you ***can*** right click on
a word document. however if you don't have the word software installed on
your computer, then when you right click on a word document in your computer
you'll not see a print option.

So my sample code is contingent upon having an application that supports
the "right clicking" on the actual file itself.

So I'm not suggesting that you right click somewhere in side of a form, I'm
suggesting that if a right click context menu is present when you right
click on the file, THEN my approach will work.

As mentioned, my sample allows printing of word, excel, pdf etc. It is a
very handy great little piece of code.

Obviously in your case it does not work.

The question you have to solve and ask yourself what application or program
have you been using over the many years to print pictures from windows?

Like I said my sample code will not work for printing of word document if
you don't have word installed

So my sample assumes that you have something that is installed for printing
of pictures and it "also" supports the right click printing context menu
option.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top