Solved

Print

Posted on 1998-12-23
3
259 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
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
hddp666 earned 20 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

912 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now