Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

705 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

18 Experts available now in Live!

Get 1:1 Help Now