Log in

View Full Version : Attachments: getting file and path



keaian
11-05-2007, 03:21 PM
When using an attachment on a form you can double click the attachment field and then add 1 to many attachments as you want to the field. However, what I am trying to do is this.

When a user add's a file to the access table, i want to be able to grab that file they attached and make a backup copy of it on a hidden share on my server. This way, if a user accidentally deletes the attached file I still have a backup of that file.

I know the code to have access create a directory on the server and copy a file to that directory, I just do not know the code to grab the file they just attached and move it.

XLGibbs
11-07-2007, 09:26 PM
If you know the code to create a location / directory you can use that to move/copy the file use the file scripting object.

Dim objFSO As FileSystemObject
DIm strSourceFolder As String, strDestFolder As String
Dim strFileName as string

Application.ScreenUpdating = False 'turn screenupdating off
Application.EnableEvents = False 'turn events off

'identify path names below:
strSourceFolder = "C:\MyFolder\" 'Source path
strDestFolder = "C:\Backup\" 'destination path

strFileName = "tesfile.xls"

objFSO.CopyFile strSourceFolder & strFileName,strDestFolder & strFileName

Set objFSO=nothing

keaian
11-08-2007, 08:33 AM
Thanks for the response Gibbs. I may have no explained exactly what i am trying to do. The code you have here moves a file.

If you have a form with an attachment object on it in 2007. You can double click on that object to bring up another window where you can view all attachments. Then you can click add and that brings up the file explorer and you can grab a file from anywhere on the computer or network and add it to the database. What I am trying to accomplish is that once they browse out for a file and choose it, I want also want to copy that same file they just chose to my hidden share. However, I am unsure of how in code to capture the file path and file name from what they chose in the access attachment dialog box.

Does this make sense?

XLGibbs
11-10-2007, 04:45 PM
Ahhh.. I see. I haven't much experience with that function in VBA for Access, nor with Access 2007.

Let me dig around and see what I can find or figure out for you.