From userform open file & print

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Hi,
I have the code below but doesnt work as it should.
My userform opens & i go to the customer in question.
In the form at TxtCustomer i have name of the customer,example TOM JONES 001
All customer files are saved here.
"C:\Users\Ian\Desktop\REMOTES ETC\DR\DR COPY INVOICES\"

So my goal is to run the code on the command button & look at customers name, then using the path print the file in question.

The below works to a point.
I am on my DATABASE WORKSHEETt, i op[en the userform & brpwse to a customer.
I use the command button to print the file in question.
The file is open in the path shown BUT when it starts to print it doesnt print the file shown on my screen BUT the DATABASE WORKSHEET.

Do you see why
Thanks



Rich (BB code):
Private Sub PrintInvoice_Click()

    Const FILE_PATH As String = "C:\Users\Ian\Desktop\REMOTES ETC\DR\DR COPY INVOICES\"
    
    If txtInvoiceNumber = "N/A" Or Len(txtInvoiceNumber) = 0 Then
                MsgBox "INVOICE N/A FOR THIS CUSTOMER", vbExclamation, "N/A INVOICE NOTICE"
    Else
        If Len(Dir(FILE_PATH & txtInvoiceNumber.Value & ".pdf")) = 0 Then
            If MsgBox("Would You Like To Open The Folder ?", vbCritical + vbYesNo, "Warning Invoice is Missing.") = vbYes Then
                CreateObject("Shell.Application").Open ("C:\Users\Ian\Desktop\REMOTES ETC\DR\DR COPY INVOICES\")
            End If
        Else
            CreateObject("Shell.Application").Open (FILE_PATH & txtInvoiceNumber.Value & ".pdf")
        End If
    End If
    ActiveWindow.SelectedSheets.PrintOut copies:=1
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Ive tried various lines of code but still does the same.

At a push the pdf doesnt even have to be opened / shown on the screen.
My main goal is to just print it.

So with the userform open.
Take note of the value in txtInvoiceNumber "in this example lets say 99"

Look here "C:\Users\Ian\Desktop\REMOTES ETC\DR\DR COPY INVOICES\" & just print Invoice 99

Thats all i need
Thanks
 
Upvote 0
Update but still im not winning.

With the line shown in Red it wants to print BUT 165 pages.
I thought that as that line of code opens the correct invoice for the customer thus adding print would do as requested.
Im missing something ^& stuck



Rich (BB code):
Private Sub PrintInvoice_Click()
    Unload Database
    Const FILE_PATH As String = "C:\Users\Ian\Desktop\REMOTES ETC\DR\DR COPY INVOICES\"
    
    If txtInvoiceNumber = "N/A" Or Len(txtInvoiceNumber) = 0 Then
                MsgBox "INVOICE N/A FOR THIS CUSTOMER", vbExclamation, "N/A INVOICE NOTICE"
    Else
        If Len(Dir(FILE_PATH & txtInvoiceNumber.Value & ".pdf")) = 0 Then
            If MsgBox("OPEN FOLDER AS INVOICE IS MISSING ?", vbCritical + vbYesNo, "INVOICE IS MISSING.") = vbYes Then
                CreateObject("Shell.Application").Open ("C:\Users\Ian\Desktop\REMOTES ETC\DR\DR COPY INVOICES\")
            End If
        Else
            CreateObject("Shell.Application").Open (FILE_PATH & txtInvoiceNumber.Value & ".pdf Print")
          
        End If
    End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,951
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top