?
Solved

Print

Posted on 1998-12-23
3
Medium Priority
?
264 Views
Last Modified: 2010-05-03
I want to have a command button in my form that when press this button, it will print out the form (printer).  I used many codes but they did not work with me correctly, like
Printer.EndDoc
Printer.Print stOutput

So please help me.
0
Comment
Question by:lovely_bird
[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
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
hddp666 earned 80 total points
ID: 1452327
The PrintForm method is used to send a bit-by-bit image of the form to the print spooler. The EndDoc method is used to finalize the print job, and release it from the spooler to the printer device. You might have to fool around with the size of the form in order to get it to print out at the correct size.

Private Sub Command1_Click()
     Form1.PrintForm
     Printer.EndDoc
End Sub


Printing text out is done by repeatedly sending print commands to the printer. After each Printer.Print command, the printer advances to the next line at the left edge of the paper. VB's default units are 'Twips'; 1 inch = 1440 Twip.

Private Sub mnuPrint2_Click()
    Printer.FontSize = 12
    Printer.CurrentX = 1440 ' 1-inch left margin
    Printer.CurrentY = 1440 ' 1-inch top margin
    Printer.Print "This is the first line to be printed."
    Printer.CurrentX = 1440 ' Twip
    Printer.CurrentY = Printer.CurrentY + 180
    Printer.Print "This is the next line to be printed."
    Printer.CurrentX = 1440
    Printer.Print "Another line. Single-spacing, this time."
    Printer.CurrentX = (Printer.ScaleWidth - Printer.TextWidth("Centered Text")) / 2
    Printer.CurrentY = Printer.CurrentY + 1440
    Printer.Font.Bold = True
    Printer.Print "Centered Text"
    Printer.EndDoc
End Sub

The default left and top of the printer object are zero (actually, the minimum values for your brand of printer). You can also set the coordinates of the printer object so that zero corresponds to the left (1-inch, or whatever) margin. When the line is finished printing, the print head moves to the next line at the left margin, not at the left edge of the paper.

Use the PrinterShow dialog box to change the printer properties.
0
 

Author Comment

by:lovely_bird
ID: 1452328
Thank you hddp666 for your answer and sorry for the delay.
I was need only this code:
Private Sub Command1_Click()
        Form1.PrintForm
        Printer.EndDoc
End Sub

But I have another question for you??
The form when it is printed, it is not printed in a full size.  I mean the form appears in a small size in the print out.  Is this normal and we can change the settings OR is there codes that I should put in the program in order to print the form in a full size??

Thank you again.
Waiting for your reply!!!
0
 
LVL 1

Expert Comment

by:hddp666
ID: 1452329
Make sure that the form is of the correct size on the computer. Unless you have a giant-sized monitor at high resolution, the form will appear to be too big for the screen.

The units of measurement for the form is vbTwip, or Twips or 1/20 of a "Printer's Point". (A "Printer's Point" is 1/72 of an inch, and the name derives from a print-shop worker (printer), not a computer's output device (printer). There term dates back long before computers, laserjets, daisywheels, &c.)

So, 1440 Twip = one inch. If you want the form to print out 7.5 inches by 10 inches (leaving 1/2" margin on all sides, about the minimum for most printers), then make sure that the height and width of the form are:

WIDTH  = 10,800
HEIGHT = 14,400

When I use these sizes at 800x600 resolution on my 21" monitor, the form STILL runs off the edge of the screen.

You might have to have one form visible on the screen (FormSm), and another (FormLg) that gets printed out. You could do this by making a duplicate of each form, scaled up with larger text, controls and so forth, and keep the duplicates invisible (Visible = False). Any changes to FormSm at run-time would be transferred, via code, to FormLg. Instead of printing the form that is visible on the screen, you would print the corresponding invisible form.

For this reason, using PrintForm is somewhat clumsy. That is why I showed you how to print to the printer object (Printer.Print), in addition to PrintForm. Another advantage of printing to the printer object, rather than using the PrintForm method, is that the resolution and quality of the printing is usually better. Sending bit-maps of fonts (letters) is not as good as the printer's built-in font quality.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

765 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