From: Martin on 18 Dec 2009 16:00 Trying to do something kind of fundamental here: Print some stuff that's displayed on a form. Just for testing purposes, I've created a form and from a menu click event, I'm showing it (MyForm.Show vbModal) In the form's Activate event there are these statements: Print "gobledygook" Print "Some stuff" Print "92oijwleijd0892uo9ij" PrintForm When I execute this, a page is printed out (on the "default" printer) but the strings shown above are NOT printed. Just for testing, I added a Label and a command button to the form. These are both printed - but not the text. What am I doing wrong?
From: Mike Williams on 18 Dec 2009 17:55 "Martin" <ironwoodcanyon(a)gmail.com> wrote in message news:7qqni5lmo53g9aj5i4orrpoh46jh5v5a6e(a)4ax.com... > Just for testing purposes, I've created a form and from a menu > click event, I'm showing it (MyForm.Show vbModal). In the > form's Activate event there are these statements [some snipped]: > Print "Some stuff" > PrintForm > When I execute this, a page is printed out (on the "default" > printer) but the strings shown above are NOT printed. > What am I doing wrong? The VB PrintForm method is inflexible and buggy and not really a good way of printing a Form, but since you are using it just for testing purposes you might as well carry on doing so, at least until you sort out how it all works and discover its limitations for yourself. Having said that, the behaviour you describe is not a bug and is in fact its documented behaviour. The PrintForm method will only print graphics that you have drawn into the Form (using Line or Circle of Print or whatever) if the Form's Autoredraw property was True when you drew them, so place the line Me.Autoredraw = True as the first line of your example code. Mike
From: Martin on 19 Dec 2009 09:56 On Fri, 18 Dec 2009 22:55:42 -0000, "Mike Williams" <Mike(a)WhiskyAndCoke.com> wrote: >"Martin" <ironwoodcanyon(a)gmail.com> wrote in message >news:7qqni5lmo53g9aj5i4orrpoh46jh5v5a6e(a)4ax.com... > >> Just for testing purposes, I've created a form and from a menu >> click event, I'm showing it (MyForm.Show vbModal). In the >> form's Activate event there are these statements [some snipped]: >> Print "Some stuff" >> PrintForm >> When I execute this, a page is printed out (on the "default" >> printer) but the strings shown above are NOT printed. >> What am I doing wrong? > >The VB PrintForm method is inflexible and buggy and not really a good way of >printing a Form, but since you are using it just for testing purposes you >might as well carry on doing so, at least until you sort out how it all >works and discover its limitations for yourself. Having said that, the >behaviour you describe is not a bug and is in fact its documented behaviour. >The PrintForm method will only print graphics that you have drawn into the >Form (using Line or Circle of Print or whatever) if the Form's Autoredraw >property was True when you drew them, so place the line Me.Autoredraw = True >as the first line of your example code. > >Mike > Thanks, Mike - that did the trick. What's strange is, I already had that property set to True (specified it when the form was created). I understand that this is not a very good way to print stuff. What is a recommended way to print a report from VB? I have a VERY simple report to generate. All it amounts to is dumping out some records that are stored in a database that the program uses. Probably 20-30 records of 3 fields each. It's just a simple list. I was thinking I would just print them to the form and then send the form to the default printer. Is there a better way?
From: Ralph on 19 Dec 2009 10:46 "Martin" <ironwoodcanyon(a)gmail.com> wrote in message news:9sppi5dehcm6k3bjpcbs8l3lt0nvg6s2qc(a)4ax.com... <snipped> > > I understand that this is not a very good way to print stuff. What is > a recommended way to print a report from VB? > > I have a VERY simple report to generate. All it amounts to is dumping > out some records that are stored in a database that the program uses. > Probably 20-30 records of 3 fields each. It's just a simple list. > > I was thinking I would just print them to the form and then send the > form to the default printer. Is there a better way? That is a classic question with IMHO two definite answers. Simply printing the form is the first thing everyone comes up with, thus everyone trys it sooner or later. And it can be made to work. But you'll soon find it to be a PITA overall and on the long run, whether this is an in-house project, commercial, or just a hobby, or even it if is just a 'VERY simple' report - These projects always grow. Sooner or later you want new features, or just add this bit here and there, or somebody will want something entirely different. Or you'll want to expand printing capability to another project and facing yet another round of all new code. Thus you have two basic options: 1) Buy a decent third party Report Generator. The prices will run from moderate to outrageous. But once you have one, you can use it everywhere, and generally do just about anything you need done. 2) Write your own Print/Report Generator. In the beginning it will seem daunting, but you'll be able to create a good all-pupose tool and at the cost of only your time. And it is here Mr. Williams is the master. Unfortunately while we have all begged him at one time or another to publish his ideas and methods in one place - no such collection exists. Especially since you initial needs are moderate. My suggestion is to Google the H out of this newsgroup for printing tips posted by "Mike Williams". It will take a day or two, but you'll soon have good ideas and good examples on where to start. Post back here if you run into problems. hth -ralph
From: Mike Williams on 19 Dec 2009 12:59
"Martin" <ironwoodcanyon(a)gmail.com> wrote in message news:9sppi5dehcm6k3bjpcbs8l3lt0nvg6s2qc(a)4ax.com... > Thanks, Mike - that did the trick. > I understand that this is not a very good way to print stuff. > I have a VERY simple report to generate. All it amounts to > is dumping out some records that are stored in a database > that the program uses. Probably 20-30 records of 3 fields > each. It's just a simple list. I was thinking I would just print > them to the form and then send the form to the default printer. > Is there a better way? Yes. There are all sorts of ways. One very simple way is to print the fields directly to the printer instead of to the Form. The ease with which you can code this depends to a great extent on exactly what it is you wish to do. For example, if some of your fields contain blocks of text that need to be word wrapped, especially if you need full left and right justification, then you will need to write more code than if the fields are all simple "one liners", but it is all very "doable" and most of it is very easy, whatever your requirements. You can print text and graphics and line drawings and jpegs and other kinds of images, all sorts of things, and you can position each of them precisely wherever you want on the page. As a very simple example, have a look at the following. The positioning in this simple case is just approximate (you need a little more code to get accurate positioning) but it should give you a taster of some of the kind of things the Printer understands: Mike Private Sub Command1_Click() Printer.Orientation = vbPRORPortrait Printer.ScaleMode = vbInches Printer.CurrentX = 0.7: Printer.CurrentY = 0.7 Printer.Font.Name = "Times New Roman" Printer.Font.Size = 16 Printer.Font.Bold = True Printer.Font.Italic = True Printer.Print "Hello World" Printer.EndDoc End Sub |