Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Print a string directly to printer from VBA?

1,127 views
Skip to first unread message

MLH

unread,
Mar 19, 2009, 3:31:23 PM3/19/09
to
Suppose I have MyString, a string-Type var
in a VBA module.

If MyString = "Hello. This is my string."

Can I print that DIRECTLY to a local printer
and eject the page from inside a VBA procedure?


Steve

unread,
Mar 19, 2009, 4:04:44 PM3/19/09
to
Create an unbound report named PrintMyString with a single textbox named
TxtMyString sized to display the max size of MyString. Put the following in
the open event of the report:
Me!TxtMyString.controlsource = " = MyString"

In your VBA procedure put:
DoCmd.OpenReport "PrintMyString"

Steve
san...@penn.com


"MLH" <CR...@NorthState.net> wrote in message
news:7575s41blun2sd39t...@4ax.com...

MLH

unread,
Mar 20, 2009, 7:40:29 AM3/20/09
to
Thanks. Although you have described a means to
produce the same end result - words on paper, ejected
from printer, etc, I'm actually asking if there's a different
way to do that. Wondering if there's a VBA command
that'll throw a string to the printer and eject the page -
no formatting. No nothing. Akin to echo Hello > LPT1
in the not-yet-forgotten DOS world.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

paii, Ron

unread,
Mar 20, 2009, 8:56:08 AM3/20/09
to

"MLH" <CR...@NorthState.net> wrote in message
news:7rv6s4lpmg0qd68a5...@4ax.com...

If you don't want to use an API call. The Shell command can used to call a
BAT file. Use that to execute your DOS commands

shell("test.bat HELLO")

Test.bat
ECHO %1
PAUSE


Tony Toews [MVP]

unread,
Mar 20, 2009, 4:26:05 PM3/20/09
to
MLH <CR...@NorthState.net> wrote:

Assuming the printer is tied to lpt1 you might be able to use the Open and write #
statements.

However you might also want to see if there are API calls available. Try doing a
search at vbnet.mvps.org.

Tony

--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/

0 new messages