I want to rename files using a VBA command stored in an MS Access subform text box. It may be of note the VBA commands are generated using a concatenation formula from a database query and copied into the text box.
This is essentially the code I'm attempting to use but I get runtime error 2434 - The expression you entered contains invalid syntax
. There may be a better way than using the eval() command.
Public Function BulkRenameFile()
Dim script As String
script = "Name ""c:\ipfimport\PE2258N2754\2620.jpg"" As ""c:\ipfimport\PE2258N2754\PE2258N2754_PH1_20141216_2620.jpg"""
BulkRenameFile = Eval(script)
MsgBox ("Photo Renaming Complete")
End Function
Any help would be much appreciated.
I post here two different routines, the 1st for renaming a single file and the second for renaming all files in a folder (or moving files from a folder to another). The 2nd accept a filter for renaming only a certain kind of files. They both use the FileSystemObject component (you must include Microsoft Scripting Runtime).
In the end i changed the field expression in my query which builds a rename command from a VBA code to a DOS one. I paste the complete datasheet column of DOS rename codes into a textbox. The text box is exported as a .txt file and then run as a .bat in windows DOS command shell.
example DOS rename command pasted into a textbox:
The final working code: