View Full Version : How to print the form using VB 6.0??
07-22-2002, 03:42 PM
Hi, How can I print a form with its contents in the same format as it is in the form?Will the background color affect the printing? Is this possible by the click of a button, or is it better to use reports to do this?Plz. help me out.
I'm designing a billing application in Vb 6.0 & here I want to print the bill for a particular purchase in a white sheet,is it possible?I also wish to know that if I use a command button to print the form then the contents of the form including the "print' button will be printed,so can I print the bill particulars alone in a specific format along with the showroom's Name & Address?
07-22-2002, 11:38 PM
The formatting of the printing output should be the same as that which you have setup on your form (or report). Reports may be better, particularly for sorting and grouping and totalling, especially for things like invoices, where the groupings/footers for Totals can both be calculated and made to appear at the bottom of every page. To do this in forms it is probably better to include a subForm within the form. Reports are in general more "printer-friendly" (especially if you can use enable shrinking and growing of the relevant text boxes) but if you particularly like the layout and look of a form then use it.
BTW Here's the full syntax for the PrintOut method as shown in your other thread.
DoCmd.PrintOut [printrange][, pagefrom, pageto][, printquality][, copies][, collatecopies]
The PrintOut method has the following arguments.
printrange One of the following intrinsic constants:
If you leave this argument blank, the default constant (acPrintAll) is assumed.
pagefrom A numeric expression that's a valid page number in the active form or datasheet. This argument is required if you specify acPages for the printrange argument.
pageto A numeric expression that's a valid page number in the active form or datasheet. This argument is required if you specify acPages for the printrange argument.
printquality One of the following intrinsic constants:
If you leave this argument blank, the default constant (acHigh) is assumed.
copies A numeric expression. If you leave this argument blank, the default (1) is assumed.
collatecopies Use True (–1) to collate copies and False (0) to print without collating. If you leave this argument blank, the default (True) is assumed.
07-23-2002, 04:02 PM
Hi, U haven't tried it yet, but anyway thanks a lot Paul.
08-04-2002, 04:33 PM
Hi, what does this doCmd mean .I tries this code but get an error message "Runtime Error :424"
What may be the problem?
The code is:
Private Sub Command1_Click()
DoCmd.PrintOut acPrintAll, acDraft, 1, False
Plz locate the error & try to slove my problem,but I can do it if u can tell me what "doCmd" is.;)
08-04-2002, 05:40 PM
The DoCmd method is commonly used in VBA, and since VBA is a subset of VB it should work OK. However in VBA the object is set automatically (or is automatic in that the declarations will be defaulting to the Form Module in use by that Form) for that DoCmd Method. Also, there has been a bug associated with this method in VBA. Having said that you could try including the object (in this case the form you want to print) with the DoCmd method, thus:-
Unfortunately printing is one of the more difficult aspects from a VB application and there are a number of approaches. Perhaps the simplest is the PrintForm method taken from MSDN.
This example uses the PrintForm method to print the current form. To try this example, paste the code into the Declarations section of a form. Place on the form any controls you want to see on the printed form, and then press F5 and click the form.
Private Sub Form_Click ()
Dim Msg ' Declare variable.
On Error GoTo ErrorHandler ' Set up error handler.
PrintForm ' Print form.
Msg = "The form can't be printed."
MsgBox Msg ' Display message.
This is the description of the PrintForm method itself:-
Sends a bit-by-bit image of a Form object to the printer.
The object placeholder represents an object expression that evaluates to an object in the Applies To list. If object is omitted, the Form with the focus is assumed to be object.
PrintForm prints all visible objects and bitmaps of the Form object. PrintForm also prints graphics added to a Form object or PictureBox control at run time if the AutoRedraw property is True when the graphics are drawn.
The printer used by PrintForm is determined by the operating system's Control Panel settings.
08-05-2002, 04:28 AM
Thank You Paul,Your reply was very helpful.So this code will print all the visible controls in the form ,right.Ok the fine.Let me try this out & contact you later.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.