AugustineWan
asked on
Error 5 relocating files. Access is denied.
When I tried to use VB to rename a PDF ( ie Name oldFile As newFile), I get the following error:
"Error generating pdf file. Please retry with these features turned off: optimize CompressObjects. Error 5 relocating files. Access is denied."
Can someone please tell me:
- Where and how to I turn off "optimze CompressObjects". ?
- What is Error 5: relocating files. ?
- Why is it telling me that "Access is denied" ?
Thanks in Advance
"Error generating pdf file. Please retry with these features turned off: optimize CompressObjects. Error 5 relocating files. Access is denied."
Can someone please tell me:
- Where and how to I turn off "optimze CompressObjects". ?
- What is Error 5: relocating files. ?
- Why is it telling me that "Access is denied" ?
Thanks in Advance
How exactly are you renaming the file? Is it still open in Acrobat when you do the rename operation?
ASKER
Acrobat is not opened when I rename the PDF file. The renaming operation is done inside function "Rename". In the function, I trap the error of "File Not Found" for sOldFile when sOldFile is being renamed because there is a possiblity that Acrobat is still writing data to sOldFile when the renaming operation is being executed.
Here are the codes:
' To Call the Function
Rename sOldFileName, sNewFileName
Function RenameFile(sOldFile As String, sNewFile As String)
Dim fso As New FileSystemObject
Dim bErrorFound As Boolean
Dim bFileError As Boolean
bErrorFound = False
bFileError = False
On Error GoTo nameError
Do While Not bFileError
If fso.FileExists(sNewFile) Then
bErrorFound = False
fso.DeleteFile (sNewFile)
Name sOldFile As sNewFile
If bErrorFound Then
bFileError = False
Else
bFileError = True
End If
Else
bErrorFound = False
Name sOldFile As sNewFile
If bErrorFound Then
bFileError = False
Else
bFileError = True
End If
End If
Loop
nameError:
bErrorFound = True
Resume Next
End Function
Here are the codes:
' To Call the Function
Rename sOldFileName, sNewFileName
Function RenameFile(sOldFile As String, sNewFile As String)
Dim fso As New FileSystemObject
Dim bErrorFound As Boolean
Dim bFileError As Boolean
bErrorFound = False
bFileError = False
On Error GoTo nameError
Do While Not bFileError
If fso.FileExists(sNewFile) Then
bErrorFound = False
fso.DeleteFile (sNewFile)
Name sOldFile As sNewFile
If bErrorFound Then
bFileError = False
Else
bFileError = True
End If
Else
bErrorFound = False
Name sOldFile As sNewFile
If bErrorFound Then
bFileError = False
Else
bFileError = True
End If
End If
Loop
nameError:
bErrorFound = True
Resume Next
End Function
The error message you are getting is not from the rename operation, but from Distiller (or Acrobat). What else are you doing just before, or during the rename operation?
ASKER
Thanks for replying. Prior to calling this function, I am creating the PDF and this is the PDF that will be renamed when the "RenameFile" function is called. The codes to create the PDF are:
With acc
strWhere = "XYZ .... " ' some conditional clause
.DoCmd.OpenReport sReport, acViewNormal, , strWhere
.DoCmd.Close acReport, modReportWriter.sReport, acSaveNo
End With
' To Call the Function
Rename sOldFileName, sNewFileName
Note that sOldFileName is assigned with the name of the PDF to be renamed.
sNewFileName is assigned with a new name for the PDF.
Where do you think the error is coming from ?
With acc
strWhere = "XYZ .... " ' some conditional clause
.DoCmd.OpenReport sReport, acViewNormal, , strWhere
.DoCmd.Close acReport, modReportWriter.sReport, acSaveNo
End With
' To Call the Function
Rename sOldFileName, sNewFileName
Note that sOldFileName is assigned with the name of the PDF to be renamed.
sNewFileName is assigned with a new name for the PDF.
Where do you think the error is coming from ?
Does the error also occur when you remove the rename function?
If it does, it's definitely related to the routine that generates the PDF, if it does not, you are probably still writing to the file while it's been renamed.
If it does, it's definitely related to the routine that generates the PDF, if it does not, you are probably still writing to the file while it's been renamed.
ASKER
The error does NOT occur when I remove the rename function. Can you tell me how I can avoid writing to the file while it's being renamed. Thanks.
I think you have to approach this differently: Don't rename the file while it's still being written. I suspect that your PDF creation routine is not done yet when you try to rename the file. You have to wait until the PDF file is completely written.
How are you creating the PDF file?
How are you creating the PDF file?
ASKER
I am using Acrobat 6.0's "Adobe PDF" printer to print the PDF file. To create the PDF file, I use the following codes::
With acc
strWhere = "XYZ .... " ' some conditional clause
.DoCmd.OpenReport sReport, acViewNormal, , strWhere
.DoCmd.Close acReport, modReportWriter.sReport, acSaveNo
End With
' To Call the Function
Rename sOldFileName, sNewFileName
Note that sOldFileName is assigned with the name of the PDF to be renamed.
sNewFileName is assigned with a new name for the PDF.
The command, "OpenReport" will use "Adobe PDF" printer to create the PDF file. Then, the "Rename" function will rename the PDF file.
You are right. I found out that the "OpenReport" process has not finished yet when the "Rename" function is called to rename the PDF file. Do you know of a way to wait or detect when a certain VB process is finished ( ie "OpenReport" )? Once I know when a process is finished, then I can call the "Rename" function.
I think that is the missing piece to the puzzle.
With acc
strWhere = "XYZ .... " ' some conditional clause
.DoCmd.OpenReport sReport, acViewNormal, , strWhere
.DoCmd.Close acReport, modReportWriter.sReport, acSaveNo
End With
' To Call the Function
Rename sOldFileName, sNewFileName
Note that sOldFileName is assigned with the name of the PDF to be renamed.
sNewFileName is assigned with a new name for the PDF.
The command, "OpenReport" will use "Adobe PDF" printer to create the PDF file. Then, the "Rename" function will rename the PDF file.
You are right. I found out that the "OpenReport" process has not finished yet when the "Rename" function is called to rename the PDF file. Do you know of a way to wait or detect when a certain VB process is finished ( ie "OpenReport" )? Once I know when a process is finished, then I can call the "Rename" function.
I think that is the missing piece to the puzzle.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your reply. You help me realize that the error occurs when the PDF Creation process has not finished yet when VB tries to run the Rename Function and vice versa.
I did not use the standard way to create the PDF because I could not find an automated method to create PostScripts from my VB application. Although I did manage to find a way to automatically transform the PostScripts into PDF from reading the Acrobat SDK Ver5.
I still hope there is a way to detect when the PDF Creation process is finished ( ie "OpenReport" ) so that I could run the Rename function afterwards. I think that could truly solve my problem!
Thanks for your help again.
I did not use the standard way to create the PDF because I could not find an automated method to create PostScripts from my VB application. Although I did manage to find a way to automatically transform the PostScripts into PDF from reading the Acrobat SDK Ver5.
I still hope there is a way to detect when the PDF Creation process is finished ( ie "OpenReport" ) so that I could run the Rename function afterwards. I think that could truly solve my problem!
Thanks for your help again.