Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I print a web page object from VBA in Access? 2

Status
Not open for further replies.

Rick46

Technical User
Sep 25, 2001
14
US
I am having a problem getting my VBA code to print a web page. The code is initiated by a button click event from within an Access form. The intent is to:
1) Start Internet Explorer.
2) Navigate to a specific web site containing a form.
3) Push data into the web form.
4) Submit the form.
5) Print the resulting web page.
6) Close and exit IE.

I cannot get the IE page to print. I have attempted the print method many ways with errors each time.
Can anyone help me with syntax of the print method to complete this function?

Thanks,
Rick46

Below is my code:

Private Sub IEForm_Click()
Dim myStart As Variant
Dim myFinish As Variant
Dim IExplorer As Object
Set IExplorer = CreateObject("InternetExplorer.Application")
'*** Start IE, go to URL
With IExplorer
.Navigate " .Visible = True
'*** Allow time for IE to navigate
myStart = Timer
Do While True
DoEvents
myFinish = Timer
If myFinish - 5 > myStart Then Exit Do
Loop
'*** Push data into IE form
IExplorer.Document.Forms(0).SENDERNAME.Value = "Doe, John"
IExplorer.Document.Forms(0).CONSIGNCOMPANY.Value = "TESTCOMPANY,INC"
IExplorer.Document.Forms(0).CONSIGNADDRESS1.Value = "999 Streetname"
IExplorer.Document.Forms(0).CONSIGNCITY.Value = "Any City"
IExplorer.Document.Forms(0).CONSIGNSTATE.Value = "IN"
IExplorer.Document.Forms(0).CONSIGNZIP.Value = "47374"
IExplorer.Document.Forms(0).CHARGEBACKCENTER.Value = "H270000"
IExplorer.Document.Forms(0).PACKAGEDSC.Value = "THIS IS A TEST"
'*** Submit form
IExplorer.Document.Forms(0).SUBMIT.Click
End With
'*** Allow time for IE to navigate
myStart = Timer
Do While True
DoEvents
myFinish = Timer
If myFinish - 5 > myStart Then Exit Do
'*** Print the displayed IE web page
IExplorer.Window.Print '<---- Cannot get to work *****
'*** Allow time for completion
myStart = Timer
Do While True
DoEvents
myFinish = Timer
If myFinish - 5 > myStart Then Exit Do
'*** Close IE
IExplorer.Quit
'*** Cleanup
Set IExplorer = Nothing
MsgBox &quot;Your barcode sheet has been printed&quot;
End Sub
 
Hers how I do it in VB from WebBrowser control.
Perhaps substituing IE for wbIntranet
Code:
Dim eQuery As OLECMDF       'return value type for QueryStatusWB
    On Error Resume Next
        eQuery = wbIntranet.QueryStatusWB(OLECMDID_PRINT)  'get print command status
        If Err.Number = 0 Then
            If eQuery And OLECMDF_ENABLED Then
                wbIntranet.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER, &quot;&quot;, &quot;&quot;    'Ok to Print?
            Else
                MsgBox &quot;The Print command is currently disabled.&quot;
            End If
        End If
        If Err.Number <> 0 Then MsgBox &quot;Print command Error: &quot; & Err.Description
    On Error GoTo 0
 
Thanks for the attempt. Now get a different error message:
&quot;Automation type not supported in Visual Basic&quot; on the Dim eQuery as OLECMDF statement. Any more clues?

ick46
 
Rick,

I took part of John solution and I got the following to work.

Private Sub Command0_Click()

Dim myStart As Variant
Dim myFinish As Variant
Dim IExplorer As Object
Set IExplorer = CreateObject(&quot;InternetExplorer.Application&quot;)
'*** Start IE, go to URL
With IExplorer
.Navigate &quot; .Visible = True
'*** Allow time for IE to navigate
myStart = Timer
Do While True
DoEvents
myFinish = Timer
If myFinish - 5 > myStart Then Exit Do
Loop
'*** Push data into IE form
' IExplorer.Document.Forms(0).SENDERNAME.Value = &quot;Doe,John&quot;
' IExplorer.Document.Forms(0).CONSIGNCOMPANY.Value = &quot;TESTCOMPANY,INC&quot;
' IExplorer.Document.Forms(0).CONSIGNADDRESS1.Value = &quot;999 Streetname&quot;
' IExplorer.Document.Forms(0).CONSIGNCITY.Value = &quot;Any City&quot;
' IExplorer.Document.Forms(0).CONSIGNSTATE.Value = &quot;IN&quot;
' IExplorer.Document.Forms(0).CONSIGNZIP.Value = &quot;47374&quot;
' IExplorer.Document.Forms(0).CHARGEBACKCENTER.Value = &quot;H270000&quot;
' IExplorer.Document.Forms(0).PACKAGEDSC.Value = &quot;THIS IS A TEST&quot;
'*** Submit form
' IExplorer.Document.Forms(0).SUBMIT.Click
End With
'*** Allow time for IE to navigate
myStart = Timer
Do While True
DoEvents
myFinish = Timer
If myFinish - 5 > myStart Then Exit Do
Loop
'*** Print the displayed IE web page


'IExplorer.Document.Forms(0).Print '<---- Cannot get to work *****
IExplorer.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER, &quot;&quot;, &quot;&quot; 'Ok to Print?



'*** Allow time for completion
myStart = Timer
Do While True
DoEvents
myFinish = Timer
If myFinish - 5 > myStart Then Exit Do
Loop
'*** Close IE
IExplorer.Quit
'*** Cleanup
Set IExplorer = Nothing
MsgBox &quot;Your barcode sheet has been printed&quot;

End Sub
 
Thank you! This one really had me stumped. I got it to work using your code. One thing, where can I get a help screen to let me know all of the sub parameters of the EXECWB command?

Thanks again
Rick46
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top