I have a number of re****ts that I want to rename programmatically.
They are all named "[re****tnumber] HP Detail". I want to change that to
"HP
Detail [re****tnumber]"
The following code filters for re****ts with the proper name structure,
determines the [re****tnumber] ****tion, 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 RenameRe****ts()
Dim obj As AccessObject, Dbs As Object, txtName As String, oldName As
String
q = 0
Set Dbs = Application.CurrentProject
For Each obj In Dbs.AllRe****ts
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, acRe****t, oldName
DoEvents
End If
Next obj
Set Dbs = Nothing
End Sub


|