-
Mar 13th, 2017, 06:22 AM
#1
Thread Starter
Lively Member
Printing Routine Error
Hi,
I have a slight issue with our invoice print routine. When we run a invoice off the code automatically prints a copy of the invoice, drivers delivery note and customer advice note. It then checks to see if the customer has a email address to sent the invoice directly to the accounts department and if not then prints a second copy of the invoice for posting. The way the routine works is it prints a 'dummy' copy of the invoice, delivery note & customer advice note to determine number of pages to a PDF printer. It then prints the actual copies to the systems default printer. This all works the only issue i am having is when the dummy deliverynote is ran its popping up asking the user to save the copy. The routine 'Call SetupBullzip(gstrFileName)' makes the dummy pdf run in the background without user intervention. It works fine for the invoice copies and customer advise notes (IE no save dialog box) but not the delivery note. It's running the PDF prior to the real copy being printed as the delivery note is printing correctly (page number X of Y is correct), i just need to suppress the PDF save dialog box.
I thought about adding a program delay but don't see why this should be required when it works fine on the invoices.
Code:
Dim lngNewInvoice As Long
Dim strPalletReferences As String
Dim strDeliveryInstructions As String
Dim strEmailText As String
SavePrinterName
' get next invoice number into lngNewInvoice
lngNewInvoice = LastInvoiceNumber + 1
' print the invoice copy
gintPageCount = 0
gintPageNumber = 0
' print invoice once to get number of pages into gintPageNumber
gstrFileName = gconstInvoiceFilePath & lngNewInvoice & ".pdf"
If CheckFileExists(gstrFileName) Then
Kill gstrFileName
End If
Call SetPrinterToBullzip
Call SetupBullzip(gstrFileName)
Call printInvoice(lngNewInvoice, True, 1)
Printer.EndDoc
ResetPrinterName
DoEvents
' now print invoice again for real
gintPageCount = gintPageNumber
gintPageNumber = 0
Call printInvoice(lngNewInvoice, True, 1)
Printer.EndDoc
gintPageCount = 0
gintPageNumber = 0
' invoice and delivery note could be different lengths
' print delivery note once to get number of pages into gintPageNumber
gstrFileName = "c:\DeliveryNote\" & lngNewInvoice & ".pdf"
If CheckFileExists(gstrFileName) Then
Kill gstrFileName
End If
Call SetPrinterToBullzip
Call SetupBullzip(gstrFileName)
Call printDeliveryNote(lngNewInvoice, True, 3)
Printer.EndDoc
ResetPrinterName
DoEvents
' now print delivery note Driver Copy for real
gintPageCount = gintPageNumber
gintPageNumber = 0
Call printDeliveryNote(lngNewInvoice, True, 3)
Printer.EndDoc
' now print delivery note Customer Copy for real
gintPageNumber = 0
Call printDeliveryNote(lngNewInvoice, True, 4)
Printer.EndDoc
-
Mar 13th, 2017, 06:49 AM
#2
Re: Printing Routine Error
Does the folder c:\DeliveryNote exist on the pc where the problem is occurring?
Does the program have write access to that folder?
-
Mar 13th, 2017, 07:27 AM
#3
Thread Starter
Lively Member
Re: Printing Routine Error
Originally Posted by DataMiser
Does the folder c:\DeliveryNote exist on the pc where the problem is occurring?
Does the program have write access to that folder?
c:\DeliveryNote is created in the 'CheckFileExists' routine if not present on the system.
Program has full write access to that directory
-
Mar 13th, 2017, 08:43 AM
#4
Re: Printing Routine Error
What is the exact error and on which line does the error occur?
-
Mar 13th, 2017, 09:10 AM
#5
Thread Starter
Lively Member
Re: Printing Routine Error
Originally Posted by Arnoutdv
What is the exact error and on which line does the error occur?
Not an error just a bug i suppose. I get a save PDF dialog box when the following code runs (at Call printDeliveryNote(lngNewInvoice, True, 3)). This should all be automated and run the PDF print in the background (setup in Call SetupBullzip(gstrFileName)). SetupBullZip is a standard routine and works for the invoice and customer advice portions of the invoice prints as expected (IE in the background).
Code:
' invoice and delivery note could be different lengths
' print delivery note once to get number of pages into gintPageNumber
gstrFileName = "c:\DeliveryNote\" & lngNewInvoice & ".pdf"
If CheckFileExists(gstrFileName) Then
Kill gstrFileName
End If
Call SetPrinterToBullzip
Call SetupBullzip(gstrFileName)
Call printDeliveryNote(lngNewInvoice, True, 3)
Printer.EndDoc
-
Mar 13th, 2017, 10:16 AM
#6
Re: Printing Routine Error
Originally Posted by martin_hop
c:\DeliveryNote is created in the 'CheckFileExists' routine if not present on the system.
Program has full write access to that directory
So I take it that means you have checked to confirm that the folder actually exists?
Creating a folder directly off the root can fail and seeing as how the code looks the same for where it works vs doesn't work I would suspect that the path/filename is the issue.
pdf generator may not be able to use the path passed to it so may prompt for one that it can.
That is the only thing I can think of off the top of my head that could explain the results you are seeing.
Have you stepped through the code to see what is happening?
-
Mar 13th, 2017, 11:28 AM
#7
Thread Starter
Lively Member
Re: Printing Routine Error
Originally Posted by DataMiser
So I take it that means you have checked to confirm that the folder actually exists?
Creating a folder directly off the root can fail and seeing as how the code looks the same for where it works vs doesn't work I would suspect that the path/filename is the issue.
pdf generator may not be able to use the path passed to it so may prompt for one that it can.
That is the only thing I can think of off the top of my head that could explain the results you are seeing.
Have you stepped through the code to see what is happening?
I've actually got this functioning now. It looks like whilst the directory was being created the code was jumping ahead even with a DoEvents after the dummy print run prior to at actually creating the directory. I added a program pause to test and this cured it. As i do not like using pauses as have seen different results from different systems i've added a quick check loop to ensure the file is created before moving on.
This has raised one other issue i've released (not sure if this should be a new thread), whilst the system now runs the dummy prints correctly, the issue is the real world printers have different print margins, which means at times where the PDF document is for example 3 pages (dummy print) but the physical print document is 4 pages the last page number is now incorrect (the fourth page reads page 4 of 3). I'd previously tried tried running the dummy print to the actual printer and then use printer.killdoc but the system will sometimes send the first page to the printer before cancelling.
My next thought was to use the ShellExecute API and run two PDF prints. The first being the dummy PDF (Doc 1) the second being the actual document (Doc 2). I then used the ShellExecute to print Doc 2 silently in the background to the printer. The only issue with this is currently it sends the document to the default system printer not the printer selected in the VB6 application. Is there a way to tell the ShellExecute to print the PDF silently in the background to the printer selected in the VB program?
-
Mar 14th, 2017, 02:16 AM
#8
Re: Printing Routine Error
Is there a way to tell the ShellExecute to print the PDF silently in the background to the printer selected in the VB program?
not with shellexecute, the only way would be to change the system default printer first, then change back
also pdf readers do not seem to be good at printing and closing, adobe reader and some others, often stay open after printing
you should be able to run the dummy print to the output printer, just use killdoc on the first run, get the number of pages then run the actual print to the same printer
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 14th, 2017, 03:48 AM
#9
Thread Starter
Lively Member
Re: Printing Routine Error
Originally Posted by westconn1
you should be able to run the dummy print to the output printer, just use killdoc on the first run, get the number of pages then run the actual print to the same printer
That was my first approach. Unfortunately as some of the prints tend to be large prints the app is sending the printout to the selected print on the dummy run prior to it reaching the Killdoc meaning i am either getting blank pages or part documents printed. The only way to stop this is to set the printer to spool after the print job has finished. I've found no way of doing this at code level (it would need to work for multiple printers) and can't change the numerous workstations as it would mean manually changing each computer and then having to monitor and maintain this as and when new hardware is added. If you have a solution along those lines that would be really handy. Otherwise i'm stuck with changing default printers and shellexecute (which i'd rather avoid if possible)
-
Mar 14th, 2017, 05:13 AM
#10
Re: Printing Routine Error
can you try something like if dummyprint then killdoc at the end of each page, should not affect the counting of pages and may prevent some pages trying to print from the spooler
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 15th, 2017, 07:10 AM
#11
Thread Starter
Lively Member
Re: Printing Routine Error
Originally Posted by westconn1
can you try something like if dummyprint then killdoc at the end of each page, should not affect the counting of pages and may prevent some pages trying to print from the spooler
I've been pulled from this project for a few days although will give that a go when i do get back on it.
-
Mar 15th, 2017, 10:50 AM
#12
Thread Starter
Lively Member
Re: Printing Routine Error
Ok so no go with an flag to indicate a dummy print unless i misunderstood. I inserted a killdoc after a new page is generated then the dummy flag was true and i kept getting an error saying printer error.
Code:
Printer.Newpage
PageCount = PageCount + 1
if DummyPrint = true Then
Printer.killdoc
end if
'continue with print routine
-
Mar 15th, 2017, 03:33 PM
#13
Re: Printing Routine Error
i kept getting an error saying printer error.
i am not sure why that would be happening, i will try to test some code later
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 16th, 2017, 03:37 AM
#14
Thread Starter
Lively Member
Re: Printing Routine Error
Originally Posted by westconn1
i am not sure why that would be happening, i will try to test some code later
Hi I've approached this with a fresh head today and the flag for a dummy print does work (tooks seconds after a good nights sleep). The Printer error only occurs when printing to OneNote which i use to save paper. Not sure why it would error with OneNote and not the physical printers or PDF printers. Any thoughts on that would be appreciated. I'd like to get to the bottom of that but at least as i'm the only one to use OneNote this will allow me to role out the update.
Thanks for the help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|