W
WorldCTZen
I have a number of reports that I want to rename programmatically.
They are all named "[reportnumber] HP Detail". I want to change that to "HP
Detail [reportnumber]"
The following code filters for reports with the proper name structure,
determines the [reportnumber] portion, then uses the docmd.rename method.
However, once the sub hits the rename line, it crashes. The error simply says
that it can't complete the operation. Error code 29068, which has no Help
dialogue.
Can anyone tell me why this is erroring, how should I correct, or is this
even possible?
Public Sub RenameReports()
Dim obj As AccessObject, Dbs As Object, txtName As String, oldName As String
q = 0
Set Dbs = Application.CurrentProject
For Each obj In Dbs.AllReports
oldName = obj.Name
If Right(obj.Name, 9) = "HP Detail" Then
Debug.Print oldName
q = InStr(obj.Name, " HP")
txtName = "Detail HP " & Left(oldName, q - 1)
Debug.Print txtName
DoCmd.Rename txtName, acReport, oldName
DoEvents
End If
Next obj
Set Dbs = Nothing
End Sub
They are all named "[reportnumber] HP Detail". I want to change that to "HP
Detail [reportnumber]"
The following code filters for reports with the proper name structure,
determines the [reportnumber] portion, then uses the docmd.rename method.
However, once the sub hits the rename line, it crashes. The error simply says
that it can't complete the operation. Error code 29068, which has no Help
dialogue.
Can anyone tell me why this is erroring, how should I correct, or is this
even possible?
Public Sub RenameReports()
Dim obj As AccessObject, Dbs As Object, txtName As String, oldName As String
q = 0
Set Dbs = Application.CurrentProject
For Each obj In Dbs.AllReports
oldName = obj.Name
If Right(obj.Name, 9) = "HP Detail" Then
Debug.Print oldName
q = InStr(obj.Name, " HP")
txtName = "Detail HP " & Left(oldName, q - 1)
Debug.Print txtName
DoCmd.Rename txtName, acReport, oldName
DoEvents
End If
Next obj
Set Dbs = Nothing
End Sub