CopyObject Rename object causing error 2103

S

Sam Davis

Hi and thanks for reading,

I have a High School Report generation application. A customer has just
installed Access 2007 and is having this problem with my Access 2003
application. This code has been working correctly for years and works
correctly on my Access 2007 development machine.

My print dialogue has a checkbox (chkBooklet) that causes each student
report to be sent indiviudally to the Printer (so it can be printed as a
booklet). In my code (see below) I copy the original report and call it
FRTemp. I then rename FRTemp to each student's name, then print the renamed
report so that each report has a different name within the printer. This
customer is getting an error 2103 (essentially means the report DNE) so it
seems either the CopyObject or the Rename is not working. The directory
containing the frontend is in a trusted location and all other code is
apparently working correctly.

Sam

Here's the relevant code segment....

If Me.chkBooklet Then
'print one student report at a time as separate jobs

'first confirm the printer
DoCmd.OpenForm "SetPrinter", acNormal, , , , acDialog
Me.Repaint
If Not (gblSetPrinterDone) Then Exit Sub

'get printer name for feedback purposes only
CurrentPrinter = Application.Printer.DeviceName

'load recordset with the studentIDs
Set db = CurrentDb
SQL = "SELECT Students.StudentID, Students.Surname & '_' & Students.Name
& '_' & students.yearlevel As FullName FROM Students WHERE " & Where & " "
SQL = SQL & "ORDER BY Students.Surname, Students.Name;"

Set rs = db.OpenRecordset(SQL, dbOpenSnapshot)

On Error GoTo Err_Booklet

'check for students
If rs.EOF Then
MsgBox "No students match the entered criteria", vbInformation,
"Print Reports"
Exit Sub
End If
rs.MoveFirst

'delete report FRTemp in case it exists
DoCmd.DeleteObject acReport, "FRTemp"

'copy FinalReport and call it FRTemp
DoCmd.CopyObject , "FRTemp", acReport, "FinalReport"

While Not (rs.EOF)

'Rename FRTemp to the student's name so it appears in the print
spool
DoCmd.Rename rs("FullName"), acReport, "FRTemp"

'print the report
DoCmd.OpenReport rs("FullName"), acViewNormal, , "StudentID='" &
rs("StudentID") & "'", acHidden
DoCmd.Close acReport, ReportName, acSaveNo

'and rename it back to old name ready for next student
DoCmd.Rename "FRTemp", acReport, rs("FullName")

rs.MoveNext
Wend

'delete report FRTemp
DoCmd.DeleteObject acReport, "FRTemp"

rs.Close
db.Close

'******************************************************************

Else
'just print the whole lot
DoCmd.OpenReport ReportName, acViewPreview, , Where
End If

Exit_Code:
Exit Sub

Err_Booklet:
If Err.Number = 7874 Then
'FRTemp DNE which is expected
Resume Next

ElseIf Err.Number = 2501 Then
'the user clicked cancel so will need to delete the current report
and close stuff
DoCmd.DeleteObject acReport, rs("FullName")
rs.Close
db.Close
Resume Exit_Code
Else
MsgBox Err.Number & vbCrLf & Err.Description, , "Print Final
Reports"
Resume Exit_Code
End If

Err_Code:

If Err.Number = 2501 Then
'do nothing as the user clicked cancel
Resume Exit_Code
Else
MsgBox Err.Number & vbCrLf & Err.Description, , "Print Final
Reports"
Resume Exit_Code
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top