EndDoc vs. NewPage

Posted on 1997-07-15
Last Modified: 2012-05-04
I have a routine that prints out notices in a loop. Every notice has some graphics and some text on it. I used to have a Printer.NewPage at the end of every notice, but, for some reason, it did not work properly. The graphics on all pages beyound the first (which printed fine) "overwrote" the text (even though the FillStyle property was set to "transparent"), and half of the fonts did not set correctly. When I replaced a NewPage with EndDoc, it worked fine - except that all these multiple print jobs in the queue tend to be slow and fill up the HD in no time. What gives ?
Question by:Sinclair

Accepted Solution

y96andha earned 100 total points
ID: 1428399
This is a bug in Visual Basic. You can fix it by making an API call to set the background mode of the text on each new page. Read more on Q145726 which I've copied below:

Microsoft Knowledge Base

PRB: Setting FontTransparent Has No Effect on Windows 95

Last reviewed: July 7, 1997
Article ID: Q145726 The information in this article applies to:

•Microsoft Visual Basic Control Creation, Learning, Professional and Enterprise editions for Windows, version 5.0 •Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0


When printing under Windows 95, the FontTransparent property of the Printer object fails to change the way that the text is printed on the background. The FontTransparent property determines whether background text and graphics are displayed in the spaces around and within characters. The Visual Basic default for this property is True, meaning that the background will display in the spaces around the text. Under Windows 95, the text will print as if FontTransparent is set to False, even though it is set to True.

Additionally, whenever a NewPage method is issued, all text on the new page will print as if FontTransparent is set to False even if it was printing correctly on the previous page.


The background mix mode, which directly relates to the Visual Basic FontTransparent property, and several other attributes of the printer device context, are modified at the start of a page by Windows 95. This is a change in behavior from Windows NT and previous versions of Windows that is not addressed properly by the Visual Basic Printer Object. The problem should only affect the 32-bit version of Visual Basic, although some cases of the 16-bit version exhibiting this behavior have been reported. For more information on the cause, please see the following article(s) in the Microsoft Windows SDK Knowledge Base:

   ARTICLE-ID: Q125696
   TITLE     : StartPage/EndPage Resets Printer DC Attributes in Windows 95


To work around the problem, call the SetBKMode Windows API function to set the background mix mode. An example is shown in the More Information section below.


Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.


The code to duplicate the problem is as follows:

1.Start Visual Basic. From the File menu, choose New Project (ALT, F, N). Form1 is created by default.

2.In the click event of the form, add the following code:

   Private Sub Form_Click()

      Printer.Line (0, 0)-(Printer.Width, Printer.Height), &HC0C0C0, BF
      Printer.CurrentX = 0
      Printer.CurrentY = 0
      Printer.FontTransparent = True
      Printer.Print "Printer.FontTransparent = " & Printer.FontTransparent
      Printer.FontTransparent = False
      Printer.Print "Printer.FontTransparent = " & Printer.FontTransparent

   End Sub

3.From the Run menu, choose start (ALT, R, S), or press the F5 key to run the program.

4.Click the form. The result should be a gray page with one line of black text in the upper left corner and another line of black text in a white box beneath the first. On Windows 95, this will yield a gray page with a white box and black text for both lines.

The following steps correct the problem in the previous example:

1.Add the following declarations to the General section of the form:

#If Win32 Then

      Private Declare Function SetBkMode Lib "gdi32"  _
      (ByVal hdc As Long, ByVal nBkMode As Long) As Long

      Private iBKMode as Long


      Private Declare Function SetBkMode Lib "GDI" (ByVal hDC As Integer _
       , ByVal nBkMode As Integer) As Integer

      Private iBKMode as Integer

#End If

      Private Const TRANSPARENT = 1
      Private Const OPAQUE = 2

2.Correct the code in the click event of the form as such:

    Private Sub Form_Click()

       Printer.Print ""
       Printer.Line (0, 0)-(Printer.Width, Printer.Height), &HC0C0C0, BF
       Printer.CurrentX = 0
       Printer.CurrentY = 0
       Printer.FontTransparent = True
       'Correctly sets the background mix mode to transparent
       iBKMode = SetBKMode(Printer.Hdc, TRANSPARENT)
       Printer.Print "Printer.FontTransparent = " & Printer.FontTransparent
       Printer.FontTransparent = False
       'Correctly sets the background mix mode to opaque
       iBKMode = SetBKMode(Printer.Hdc, OPAQUE)
       Printer.Print "Printer.FontTransparent = " & Printer.FontTransparent

    End Sub

3.From the Run menu, choose start (ALT, R, S), or press the F5 key to run the program.

4.Click the form. The text should now print as expected.

Author Comment

ID: 1428400
Thanks, y96andha ! This will help my HD to relax a bit...
Bill Gates strikes again...

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Put text in a picture ASP.NET C# 2 56
Sending a email via excel using vba 6 79
vb6 connector to mongodb 2 81
Passing a Text Box name to a Sub 6 96
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

805 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