Solved

coding for printing

Posted on 2000-03-14
5
144 Views
Last Modified: 2010-05-02
i would like to ask if there's anyone who can provide or suggest a code for printing in VB.

i have a program that has a menu -> file ->print

so wat should i write for the coding of my "mnuFilePrint" 's click event?
0
Comment
Question by:poeyser
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:Foyal
ID: 2618632
Use the Printer object to print to the default printer for the system... You can also change the default printer by selecting a printer from the Printers collection.

'set up what you want to print...

'print strings...
Printer.Print "Here is some text."

'or string variables...
S = "Here is some more text."
Printer.Print S

'use vb constants for alignment...
Printer.Print vbTab & "indented line."

'print formatted strings
Printer.Print Format(Now, "mmm dd,yyyy")

Printer.EndDoc 'print it

Look for this stuff in the help files.
There are alot of properties you can
access also with the common dialog control. (CommonDialog1.ShowPrinter)

0
 
LVL 1

Expert Comment

by:csameer1
ID: 2852820
another important question is what you want to print?
0
 
LVL 3

Expert Comment

by:Foyal
ID: 2854314
csameer1 is right. If you want to print some types of pictures you may need to go to the api. You can, however, print a picture which is contained in a picture box by using the printer.paintpicture method. Hope this helps.
0
 
LVL 1

Expert Comment

by:csameer1
ID: 3034664
what do you want to print?
0
 
LVL 3

Accepted Solution

by:
Foyal earned 50 total points
ID: 3037454
Add a common dialog control to your project.

Private Sub mnuFilePrint_Click()

    On Error GoTo ErrHandler
   
    CommonDialog1.ShowPrinter
   
    PrintWhatever


ExitFilePrint:

    Exit Sub

ErrHandler:

    If Err = 32755 then Exit Sub

    msgbox "Error " & CStr(Err) & ": " & Err.Description
    Resume ExitFilePrint

End Sub

Private Sub PrintWhatever()

    On Error GoTo ErrHandler

    Printer.Print "whatever"
    Printer.EndDoc

ExitPrintWhatever:

    Exit Sub

ErrHandler:
 
    msgbox "Error " & CStr(Err) & ": " & Err.Description
    Resume ExitPrintWhatever

End Sub

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

688 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