?
Solved

Print

Posted on 1998-12-23
3
Medium Priority
?
265 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Suggested Courses

650 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