Hi guys!
I am working with some PDF's who are merged by some .dll. Merging process works fine, but if I want, for example, do the process again, I want old files (there are 3 of them) to be overwritten by the new ones, I am getting an error when an old file is about to be deleted (on kill method),
the error says: Run-time error 70, permission denied
I tried to use setAttr myFile, vbNormal before kill method, still getting the same error.
Also when I tried to delete files manually in a directory I get the message that file is open in Microsoft access, so at least I know why I can't delete it, but I DON'T KNOW when access opens those 3 files. In my DoCmd.OutputTo line there is also "False" on Autostart argument...
Files seem to be overwritten only when I reopen whole access application.
Here is my code where the problem occurs:
strFile = GetAppPath & stDocName & "_racunid=" & Me.RacunID & ".pdf"
If Len(Dir(strFile)) > 0 Then
SetAttr strFile, vbNormal
Kill strFile
End If
DoCmd.OpenReport stDocName, acPreview, , "RacunID=" & Me.RacunID
DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, strFile, False
files(i) = outPath & stDocName & "_racunid=" & Me.RacunID & ".pdf"
DoCmd.Close acReport, stDocName
Also, here is a code from my .dll part: (this part of merging PDF's comes after outputing report to pdf)
Public Sub MergePDFs(ByVal fileNames() As String, ByVal sPath As String)
Dim pdfReaderList As List(Of PdfReader) = New List(Of PdfReader)()
For Each filePath As String In fileNames
Dim pdfReader As PdfReader = New PdfReader(filePath)
pdfReaderList.Add(pdfReader)
Next
Dim document As Document = New Document(PageSize.A4, 0, 0, 0, 0)
Dim writer As PdfWriter = PdfWriter.GetInstance(document, New FileStream(sPath & "Ukupan racun.pdf", FileMode.OpenOrCreate))
document.Open()
For Each reader As PdfReader In pdfReaderList
For i As Integer = 1 To reader.NumberOfPages
Dim page As PdfImportedPage = writer.GetImportedPage(reader, i)
document.Add(iTextSharp.text.Image.GetInstance(page))
Next
Next
document.Close()
End Sub
If anyone has any idea what could cause problem, I appreciate it ...
Thanks in advance!
I am working with some PDF's who are merged by some .dll. Merging process works fine, but if I want, for example, do the process again, I want old files (there are 3 of them) to be overwritten by the new ones, I am getting an error when an old file is about to be deleted (on kill method),
the error says: Run-time error 70, permission denied
I tried to use setAttr myFile, vbNormal before kill method, still getting the same error.
Also when I tried to delete files manually in a directory I get the message that file is open in Microsoft access, so at least I know why I can't delete it, but I DON'T KNOW when access opens those 3 files. In my DoCmd.OutputTo line there is also "False" on Autostart argument...
Files seem to be overwritten only when I reopen whole access application.
Here is my code where the problem occurs:
strFile = GetAppPath & stDocName & "_racunid=" & Me.RacunID & ".pdf"
If Len(Dir(strFile)) > 0 Then
SetAttr strFile, vbNormal
Kill strFile
End If
DoCmd.OpenReport stDocName, acPreview, , "RacunID=" & Me.RacunID
DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, strFile, False
files(i) = outPath & stDocName & "_racunid=" & Me.RacunID & ".pdf"
DoCmd.Close acReport, stDocName
Also, here is a code from my .dll part: (this part of merging PDF's comes after outputing report to pdf)
Public Sub MergePDFs(ByVal fileNames() As String, ByVal sPath As String)
Dim pdfReaderList As List(Of PdfReader) = New List(Of PdfReader)()
For Each filePath As String In fileNames
Dim pdfReader As PdfReader = New PdfReader(filePath)
pdfReaderList.Add(pdfReader)
Next
Dim document As Document = New Document(PageSize.A4, 0, 0, 0, 0)
Dim writer As PdfWriter = PdfWriter.GetInstance(document, New FileStream(sPath & "Ukupan racun.pdf", FileMode.OpenOrCreate))
document.Open()
For Each reader As PdfReader In pdfReaderList
For i As Integer = 1 To reader.NumberOfPages
Dim page As PdfImportedPage = writer.GetImportedPage(reader, i)
document.Add(iTextSharp.text.Image.GetInstance(page))
Next
Next
document.Close()
End Sub
If anyone has any idea what could cause problem, I appreciate it ...
Thanks in advance!