Solved

coding for printing

Posted on 2000-03-14
5
143 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
  • 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

831 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