Hi. I have a table with a field for the temporary file name, which includes the original (temporary) folder path, the name of the document and the file extension (TempPicturePathName) and another field with the new folder path and new name (FinalPicturePathName; the final folder path is different than the original folder path).
I'm stuck at the Name function (line 24 of code), as the debugger does not like Name OldPathName As New PathName
Some further info: table is named tblTempPictures; field with old path name is TempPicturePathName (sample of field contents: C:\Users\T\Documents\My Databases\RenamePlay\A.pdf); field with new path name = FinalPicturePathName (sample of C:\Users\T\Documents\My Databases\RenamePlay\AsRENAMED\Test_A.pdf) --I know a pdf is not a picture, I'm just using these names to follow along with code - I'll change the table name and fields later.
I'm stuck at the Name function (line 24 of code), as the debugger does not like Name OldPathName As New PathName
Some further info: table is named tblTempPictures; field with old path name is TempPicturePathName (sample of field contents: C:\Users\T\Documents\My Databases\RenamePlay\A.pdf); field with new path name = FinalPicturePathName (sample of C:\Users\T\Documents\My Databases\RenamePlay\AsRENAMED\Test_A.pdf) --I know a pdf is not a picture, I'm just using these names to follow along with code - I'll change the table name and fields later.
Code:
Private Sub cmdRename_Click()
'This code MAY FAIL IF THE USER DOES NOT HAVE WRITE PERMISSION TO THE FOLDER THE DOCUMENTS ARE TO BE MOVED TO
'With Loop through recordset
Dim i As Integer
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim tbl As String
Set myObject = New Scripting.FileSystemObject
Set db = CurrentDb
tbl = "tblTempPictures"
Set rs = db.Openrecordset("tblTempPictures")
For i = 0 To rs.RecordCount - 1
Dim OldPathName As String
Dim NewPathName As String
OldPathName = rs.Fields("TempPicturePathName")
NewPathName = rs.Fields("FinalPicturePathName")
Name OldPathName As NewPathName
rs.MoveNext
Next i
Counter = Counter + 1
' Clean up
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
Set myObject = Nothing
Set mySource = Nothing
MsgBox "Listed " & Counter & " Files in Table."
rs.Close
Set rs = Nothing
db.Close
End Sub