Solved

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

Posted on 2004-10-07
7
204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 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…
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

628 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