R
Rob Parker
I'm trying to rename a report (which is not open) prior to sending it via
SendObject; I'm doing this so that the .snp file has a meaningful name to
the receipient.
According to the Help file, I should be able to do this quite simply:
<quote from help file for Rename method>
expression.Rename(NewName, ObjectType, OldName)
....
NewName Required Variant. A string expression ...
The following example renames the Employees table.
DoCmd.Rename "Old Employees Table", acTable, "Employees"
<end quote>
My code is as follows:
...
Dim strStaff As String
...
'rename report to staff name
DoCmd.Rename strStaff, acReport, "rptTimetable"
'send report
DoCmd.SendObject acSendReport, strStaff, acFormatSNP, , , , "Semester
Timetable", strEmailText, True
'rename report to default name
DoCmd.Rename "rptTimetable", acReport, strStaff
...
When I entered the code, intellisense gives acReport as a valid parameter
for the object type. strStaff contains a string which is a valid name for a
report (eg "HILLIARK").
When the code runs, I get Error 29068 "TimeTables cannot complete this
operation. You must stop the code and try again." when it gets to the first
DoCmd.Rename statement. Changing the declaration of strStaff to Variant has
no effect (and I don't believe it should be necessary to do so anyway).
Opening the report prior to the Rename command gives (as I expected) a
different error, Error 2009 "You can't rename the database object
'rptTimetable' while it's open."
Why does DoCmd.Rename fail? And, if I can't get this to work, how can I
rename the report before sending it?
TIA,
Rob
SendObject; I'm doing this so that the .snp file has a meaningful name to
the receipient.
According to the Help file, I should be able to do this quite simply:
<quote from help file for Rename method>
expression.Rename(NewName, ObjectType, OldName)
....
NewName Required Variant. A string expression ...
The following example renames the Employees table.
DoCmd.Rename "Old Employees Table", acTable, "Employees"
<end quote>
My code is as follows:
...
Dim strStaff As String
...
'rename report to staff name
DoCmd.Rename strStaff, acReport, "rptTimetable"
'send report
DoCmd.SendObject acSendReport, strStaff, acFormatSNP, , , , "Semester
Timetable", strEmailText, True
'rename report to default name
DoCmd.Rename "rptTimetable", acReport, strStaff
...
When I entered the code, intellisense gives acReport as a valid parameter
for the object type. strStaff contains a string which is a valid name for a
report (eg "HILLIARK").
When the code runs, I get Error 29068 "TimeTables cannot complete this
operation. You must stop the code and try again." when it gets to the first
DoCmd.Rename statement. Changing the declaration of strStaff to Variant has
no effect (and I don't believe it should be necessary to do so anyway).
Opening the report prior to the Rename command gives (as I expected) a
different error, Error 2009 "You can't rename the database object
'rptTimetable' while it's open."
Why does DoCmd.Rename fail? And, if I can't get this to work, how can I
rename the report before sending it?
TIA,
Rob