Solved

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

Posted on 2004-10-07
7
200 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

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

Suggested Solutions

Title # Comments Views Activity
Restricting text box entry from \/:?<>"| 9 76
Access query that references subform 5 43
VB6 - Convert HH:MM into Decimal 8 51
Passing a Text Box name to a Sub 6 76
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…
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…

895 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

13 Experts available now in Live!

Get 1:1 Help Now