Error -2147024864 MS Access report to PDF with Bullzip (1 Viewer)

Hello1

Registered User.
Local time
Tomorrow, 00:37
Joined
May 17, 2015
Messages
271
Hello,

I have a rather odd problem with MS Access and bullzip. Im converting one by one report (invoice) to PDF with bullzip. The whole process in Access goes without any errors.
However, sometimes I get the error message from the title in bullzip with the next text:

"Error -2147024864: The process cannot access the file 'C:\Users\aaa\AppData\Local\Temp\Bullzip\PDF Printer\Cleaned-20210803.tmp' because it is being used by another process.

Source: mscorlib

Internal hint: Cleanup: Delete temp folders from old sessions (test file date).
Developers: You can hide this message with the "suppreserrors" setting."

When this happens Access continues to work and finishes the procedure but my PDF files get messy.
What happens is that I store the file under the invoice number 0001 as file name but inside the file is actually the invoice 0002.
Below is my code and it works fine as far as I know and it shouldnt mix the invoices. It somehow seems like that bullzip skips one or gets stuck when the error message appears.


Code:
If Not MyRs.EOF Then
    MyRs.MoveFirst
        While Not MyRs.EOF
            IdPotr = MyRs!IdPotrosaca
            FileName = Format(IdPotr, "000000") & "_" & Left(MyRs!TekuciMje, 2) & "_" & Right(MyRs!TekuciMje, 2)
            FilePath = "D:\Racuni_PDF\" & Right(MyRs!TekuciMje, 4) & "god\" & FileName & ".pdf"
            If IsLoaded("rptRacuniA4") Then
                DoCmd.Close acReport, "rptRacuniA4", acSaveYes
            End If
            DoCmd.OpenReport "rptRacuniA4", acViewPreview, , "IdPotrosaca = " & IdPotr & "", acHidden
            If IdPotr <> IdPotrPriExp Then
                MsgBox "Some random message", vbCritical, "Title"
                Exit Sub
            End If
            PrintInvoice FilePath
            If IdPotr <> IdPotrPriExp Then
                MsgBox "Some random message", vbCritical, "Title"
                Exit Sub
            End If
            DoCmd.Close acReport, "rptRacuniA4", acSaveNo
        MyRs.MoveNext
        Wend
End If


Code:
Sub PrintInvoice(Optional sFileName As String = "", Optional confirmOverwrite As Boolean = False)
Dim oPrinterSettings As Object
Dim oPrinterUtil As Object
Dim sPrintername As String
Dim sFullPrinterName As String
Application.Printer = Application.Printers("Bullzip PDF Printer")
Set oPrinterSettings = CreateObject("Bullzip.PdfSettings")
Set oPrinterUtil = CreateObject("Bullzip.PdfUtil")
sPrintername = oPrinterUtil.DefaultPrintername
oPrinterSettings.Printername = sPrintername
With oPrinterSettings
.SetValue "Output", sFileName
.SetValue "ConfirmOverwrite", "no"
.SetValue "ShowSettings", "never"
.SetValue "ShowPDF", "no"
.WriteSettings True
End With
DoCmd.PrintOut (acPages)
End Sub

I have to mention that this mess up doesnt happen always when the error message appears.
"Internal hint: Cleanup: Delete temp folders from old sessions (test file date)." - should I maybe try to remove the C:\Users\aaa\AppData\Local\Temp\Bullzip\ folder before entering the bullzip export procedure? But if the file is really in use I doubt it will let me remove the folder.
Also, only one user is doing this so thats why its rather strange, no one else is using the export.
I tried to post on bullzips forum but it seems dead, more than 2 weeks and post still not approved.

Thanks in advance. If more info is needed I will add.
 
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 22:37
Joined
Sep 21, 2011
Messages
14,048
I do not understand why you just do not use Access? How old is your Access?, I can do this on 2007
 

Hello1

Registered User.
Local time
Tomorrow, 00:37
Joined
May 17, 2015
Messages
271
Because of the file size. When I do it with bullzip its about 50-60 KB per PDF file, while with access its about 250-300 KB.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:37
Joined
May 7, 2009
Messages
19,169
maybe a remnant of your file is being used and still in memory.
try killing in Taskmanager or reboot your pc and retry.
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:37
Joined
Sep 21, 2011
Messages
14,048
So is it a timing issue? You are still printing one pdf when you try and print the second?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:37
Joined
May 7, 2009
Messages
19,169
or maybe the temp file will be released if you released the printer object you created?
 

isladogs

MVP / VIP
Local time
Today, 22:37
Joined
Jan 14, 2017
Messages
18,186
Because of the file size. When I do it with bullzip its about 50-60 KB per PDF file, while with access its about 250-300 KB.
With the size of hard disks these days does that really matter?

If you think it does, then have you tried using the Minimum size option when printing to PDF from Access.

1627986681367.png


This can significantly reduce PDF file size and is probably doing what Bullzip does
 

Hello1

Registered User.
Local time
Tomorrow, 00:37
Joined
May 17, 2015
Messages
271
So is it a timing issue? You are still printing one pdf when you try and print the second?
or maybe the temp file will be released if you released the printer object you created?
I'm really not sure. I was thinking about killing the process before starting a new print but not sure if that's the right way to go.
I could suppress the error but then I won't know when does it mess up the files. After closing that error box everything seems to be working fine until after some time it happens again.

arnelgp I could try your suggestion, sounds worth a shot. The crappy thing is I can't really test it.
So I would go with setting oPrinterSettings = Noting or closing it? I didn't really do much with objects, would the methods be the same as for a recordset?

With the size of hard disks these days does that really matter?

If you think it does, then have you tried using the Minimum size option when printing to PDF from Access.

View attachment 93337

This can significantly reduce PDF file size and is probably doing what Bullzip does
I tried this but it doesn't reduce the size even close to what bullzip does.
I know it's not a big size but these PDF files are being sent by mail and with our still crappy internet speeds it does matter a lot, especially when there's over 200 of the PDF files.
 

isladogs

MVP / VIP
Local time
Today, 22:37
Joined
Jan 14, 2017
Messages
18,186
Is the PDF quality as good in the much smaller files?
Of course, you could just zip the files before emailing them!
 

Hello1

Registered User.
Local time
Tomorrow, 00:37
Joined
May 17, 2015
Messages
271
Is the PDF quality as good in the much smaller files?
Of course, you could just zip the files before emailing them!
You would be surprised about the quality actually. Zipping doesn't really reduce the size. I just tried it now, from 345KB it reduced it to 336KB
Also, printing to PDF and saving the report as PDF makes a difference in size too, printing is smaller (it's size is 250KB, the same report used).
Same report for bullzip 106KB.
Images on reports stay sharp in both exports bullzip and Microsoft printing to PDF, while the save as PDF method has a pretty blurry picture
 

isladogs

MVP / VIP
Local time
Today, 22:37
Joined
Jan 14, 2017
Messages
18,186
Fair enough. Just the error to solve then....😉
 

Hello1

Registered User.
Local time
Tomorrow, 00:37
Joined
May 17, 2015
Messages
271
Just yeah 😅 🙈
If I don't manage to, guess I will have to use the access export again 😁
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 17:37
Joined
Feb 28, 2001
Messages
27,001
Error -2147024864 is hexadecimal 80070020, which says three things:

The fact that it is 0x80... rather than 0xC0... means it is an error but not a "SEVERE ERROR." This in turn means that an error handler might be able to trap and ignore the error.
The "..07" is going to depend on the order in which some utility library was installed. I.e. site-dependent and unpredictable.
The "...0020" is ERROR_SHARING_VIOLATION which means something you are trying to do is incompatible with something another user - or another of your own threads - is trying to do with the file. Given your discussion, Access and the printer are trying to touch the file in question at the same time. On the odd theory that this is a timing issue, try changing that code you showed us earlier like this (but see comments later about more to be done besides this):

Code:
            If IdPotr <> IdPotrPriExp Then
                MsgBox "Some random message", vbCritical, "Title"
                Exit Sub
            End If
            DoCmd.Close acReport, "rptRacuniA4", acSaveYes
            DoEvents
            PrintInvoice FilePath

I think part of the problem is that your call to PrintInvoice was originally issued before you closed the report. But looking at the code for the print subroutine, it appears there may be a way for you to use that BullZip feature to print/zip a closed file. What you might have to do is make a closed file out of the report, zip it with your PrintInvoice routine, and then delete the original "raw" report. But... if you can do this, you would not have the file still open when you do the PrintInvoice function, and that "file still in use" situation is what the error code is telling you.

I can see that it MIGHT be a timing issue since printers typically run as parallel threads. Therefore, depending on factors that might be very hard to isolate, sometimes Access and Bullzip step on each others toes while dancing. Thinking back on when you occasionally get this error, do your recall whether it was always big files? Always small files? You MIGHT even get away with the original code by putting a DoEvents call either before or after the original PrintInvoice call. That's part of the problem with using external utilities that are in separate threads.
 

Hello1

Registered User.
Local time
Tomorrow, 00:37
Joined
May 17, 2015
Messages
271
I think part of the problem is that your call to PrintInvoice was originally issued before you closed the report.
In order to print the report to PDF with bullzip I need it to be open before entering the PrintInvoice routine, but very possible that I misunderstood you.
But looking at the code for the print subroutine, it appears there may be a way for you to use that BullZip feature to print/zip a closed file. What you might have to do is make a closed file out of the report, zip it with your PrintInvoice routine, and then delete the original "raw" report.
To be honest I'm very unfamiliar with this and I'm not very sure I understood. So I could use access to make the PDF files without bullzip and then print those same PDF files again to PDF with bullzip? I just tried it manually and it does work (a bit different page size). I save from access the report to PDF with the size of 220KBs and then I open the PDF file and print it with bullzip to PDF again, the size reduces to 85KBs.
Thinking back on when you occasionally get this error, do your recall whether it was always big files? Always small files?
I did't find any pattern. Usually all the files are of the same size (1-2KBs difference). It does somehow appear to happen at the very beginning, when just starting the printing, but not always.

Thanks for the tips. I will include the DoEvents and set the objects to nothing after every print. After that I can leave it to the customer to try and wait for it. Didn't manage to reproduce the same error on my machine.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 17:37
Joined
Feb 28, 2001
Messages
27,001
Unfortunately, I am not familiar with BullZip so my best advice is if you have a manual for it, check whether you have the option to give it a file that is closed in order to zip it. If you really DO need the file to be open, then the DoEvents experiment is your best shot to avoid Access and Bullzip stepping on each other.
 

Hello1

Registered User.
Local time
Tomorrow, 00:37
Joined
May 17, 2015
Messages
271
Added the DoEvents, set objects to nothing on the end of PrintInvoice procedure also set the default printer back to the original one after using bullzip. So I will follow and see if they report any new errors.
Thanks guys
 

Users who are viewing this thread

Top Bottom