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.Print stOutput

So please help me.
Who is Participating?
hddp666Connect With a Mentor Commented:
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()
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"
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.
lovely_birdAuthor Commented:
Thank you hddp666 for your answer and sorry for the delay.
I was need only this code:
Private Sub Command1_Click()
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!!!
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.