VBA code to Copy a file and check if file exists

Rattlesnake

Registered User.
Local time
Today, 11:26
Joined
Sep 19, 2002
Messages
31
Hi,
I have an Access application that contains a form , where the user will selects a Picture and add comments about that picture.
I have decided to place only the Path to the Picture in the database and not the actual picture , as I have read that the Database size increases alarmingly when storing the picture in the database.
I have a folder called PICTURES ,in the same directory as the Access database.The Access Database is stored on a File server.

What I want is that When the users selects a Picture using a Dialogbox (i have already code for this), the picture file should be COPIED to this PICTURE folder and then the path in the table should be saved as "PICTURES\Picture1.jpg"

I want help with the code that will do the COPYING of the file to the PICTURE folder. If a ile with the same name already exists , it should add a random number to the file name and then save. for if Pic1.jpg , already exists it should change the to Pic14.jpg or something like that.
Moreover , how can I get only the FILENAME (without the path) when the user selects a file.
For e.g. if the path is C:\Images\PIC2.JPG , how do I get onyl PIC2.JPG


Thanks for your help.
 
Searching the forum is a great way to discover and learn the answers to your Access programming questions. As long as the found links still work!

Code:
Public Function ParseFileName(sFile As String) As String
On Error GoTo Err_ParseFileName

    Dim sPath As String
    
    sPath = sFile
    
    Do While Right$(sPath, 1) <> "\"
    sPath = Left$(sPath, Len(sPath) - 1)
    Loop
    
    ParseFileName = Mid$(sFile, Len(sPath) + 1)
 
Exit_ParseFileName:
    Exit Function

Err_ParseFileName:
    MsgBox Err.Number & " -" & Err.Description
    Resume Exit_ParseFileName
 
End Function
 

Users who are viewing this thread

Back
Top Bottom