Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-10-07
7
Medium Priority
?
205 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

704 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