TheSearcher
Registered User.
- Local time
- Today, 03:50
- Joined
- Jul 21, 2011
- Messages
- 358
I wrote a procedure to rename a file and place it in a new directory. I am using the NAME statement to do this. I keep getting a "File not found" error on the first record.
I tried it with the destination directory being blank.
I tried it with the destination directory having the same files as the original directory.
I tried renaming the files exactly where they are without involving another directory.
Same error every time. The files are definitely there. My code is below. Can anyone see what I'm doing wrong?
I tried it with the destination directory being blank.
I tried it with the destination directory having the same files as the original directory.
I tried renaming the files exactly where they are without involving another directory.
Same error every time. The files are definitely there. My code is below. Can anyone see what I'm doing wrong?
Code:
Public Sub RenameFiles()
Dim sql1 As String, OldName As String
Dim rs As Recordset
Dim db As Database
Set db = CurrentDb
sql1 = "SELECT t_test.OldName, t_test.NewName FROM t_test ORDER BY t_test.OldName;"
Set rs = db.OpenRecordset(sql1)
rs.MoveFirst
Do Until rs.EOF
OldName = rs("OldName")
NewName = rs("NewName")
Name OldName As NewName
rs.MoveNext
Loop
rs.Close
MsgBox "Complete"
End Sub
Table: t_test
OldName NewName
H:\Data\Test\20240501_SmithJohn_OT_243.pdf H:\Data\Test\SmithJohn_20240501_OT_243.pdf
H:\Data\Test\20240501_JonesJoe_OT_219.pdf H:\Data\Test\JonesJoe_20240501_OT_219.pdf