Rename image files stored on the hard disk

RCurtin

Registered User.
Local time
Today, 05:05
Joined
Dec 1, 2005
Messages
159
Hi,
I have a database of engineering drawings with fields such as drawing number, drawing name etc. I also have the corresponding image files but the filenames are different to the drawing names.

I have code (thanks to ghudson!) that will open the image file and put the filename into a text box.

What I would like to know is
- is it possible to open this file and change the filename of the image itself to the drqwing name stored in the textbox?
- if so could anyone give me pointers on where to find out about this.

Thanks,
RCurtin

P.S. Is there an API anywhere. For some reason I dont have the VBA help files on my computer and the object browser doesn't really tell you how to use the objects and associated procedures.
 
This will allow you to rename a file, just supply the PATH, CurrentFileName, NewFileName:
Code:
Sub RenameFile(Pth As String, FN1 As String, FN2 As String)
REM Posted by FoFa from "The Lone Star State"
Dim fso, f, P1
On Error GoTo RNF_ERR
Set fso = CreateObject("Scripting.FileSystemObject")
If Right(Pth, 1) <> "\" Then
  P1 = Pth & "\"
Else
  P1 = Pth
End If
Set f = fso.GetFile(P1 & FN1)
f.Name = FN2
Set f = Nothing
Set fso = Nothing
Exit Sub
RNF_ERR:
  MsgBox "ERROR renaming file " & FN1 & " to " & FN2, vbCritical, "Rename File Error"
  MsgBox "You can manually rename the file to " & FN2 & " then send it", vbInformation, "Possible Action"
  Exit Sub
End Sub

NOTE - This assumes the NewFileName does NOT exist currently. If the file name you are renaming to exist, it will error.
 
Last edited:
Search the Access help files for the Name Statement.

Code:
Name OldName As NewName
 

Users who are viewing this thread

Back
Top Bottom