Solved

Printing with the web browser is doubleing up on the first file

Posted on 2004-10-07
7
202 Views
Last Modified: 2013-12-26
Hello All,

In the code that I will post below is what I am using to print out 'x' number of htm files with out prompting the user. It is being used inside a class that is called from an exe that is run nightly.

The main problem is that the htm file that is created first '1.htm' is printed twice and then the htm file that is created last '22.htm' is not printed at all.  

I have tried various things like adding loops that just do application.doevents figureing that it will give the browser time to fully load all of the htm files but it doesn't seem to help. It just seems to fix the orginal problem but then it only prints everyother file.

The code below is what I used in the orginal version of this.

 Public Sub PrintInvoice(ByVal strInvoiceHTMLFile As String, Optional ByVal strPrinterName As String = "")

        ' Check file exists
        If Dir(strInvoiceHTMLFile) = "" Then Exit Sub

        ' Set printer
        If strPrinterName <> "" Then
            m_SetWindowsDefaultPrinter(strPrinterName)
        End If

        ' Load file into WebControl
        m_objWebBrowser.Navigate(strInvoiceHTMLFile)

        ' Wait for WebControl to load the file
        Dim status As SHDocVw.OLECMDF
        status = m_objWebBrowser.QueryStatusWB(SHDocVw.OLECMDID.OLECMDID_PRINT)
        While status <> SHDocVw.OLECMDF.OLECMDF_SUPPORTED And status <> SHDocVw.OLECMDF.OLECMDF_ENABLED And status <> 3
            Application.DoEvents()
            status = m_objWebBrowser.QueryStatusWB(SHDocVw.OLECMDID.OLECMDID_PRINT)
        End While


        ' Send Print command
        ' NOTE: This print command using OLECMDEXECOPT_DONTPROMPTUSER, sends to the Windows Default Printer
        m_objWebBrowser.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER)
        Application.DoEvents()

    End Sub
0
Comment
Question by:ridodds
7 Comments
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 12256565
It may help to provide the loop that prints the files.
0
 

Author Comment

by:ridodds
ID: 12257650
Well this line is all I call and it is just above the End Sub of my orginal posting.

 m_objWebBrowser.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER)

This is what sends the command to print.
0
 

Author Comment

by:ridodds
ID: 12257666
I will add that when this Sub is called it is receiving the files in order and only one copy of each. I have walked through it many times and each time the first file is only pasted in the first time and the last file is passed in as well.
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 12258008
Try this use timer



Option Explicit
Private Sub Timer1_Timer()
Timer1.Enabled = False
 m_objWebBrowser.Navigate strInvoiceHTMLFile
End Sub

Private Sub  m_objWebBrowser_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Debug.Print pDisp
If (pDisp =  m_objWebBrowser) Then
m_objWebBrowser.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER)
End If
End Sub




Public Sub PrintInvoice(ByVal strInvoiceHTMLFile As String, Optional ByVal strPrinterName As String = "")

       ' Check file exists
       If Dir(strInvoiceHTMLFile) = "" Then Exit Sub

       ' Set printer
       If strPrinterName <> "" Then
           m_SetWindowsDefaultPrinter(strPrinterName)
       End If

       ' Load file into WebControl
      Timer1.Interval = 1
      Timer1.Enabled = True
       
   End Sub
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12989054
PAQed with no points refunded (of 500)

modulo
Community Support Moderator
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

685 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