[AccessD] Storing Files in Directories

Nicholson, Karen cyx5 at cdc.gov
Thu Aug 18 13:24:30 CDT 2005


This is code that I have to create directories and then move files into
the directories.  My TN number is my unique identifier which creates a
unique directory if needed.  How are you grabbing your unique file name?
Looks like a date.  How about Date and Time so you don't get duplicate
file names?

Private Function fcnMakeDestFolder(vTNNum As Variant) As Boolean
On Error GoTo ErrorHandler

    Dim fsoDir As Object
    Dim strMsgText As String

    strMsgText = "Creating Final Project Destination Folder"
    DoCmd.OpenForm "Status Display", , , , acFormReadOnly, acDialog,
strMsgText
    
    'Check and/or create the manufacturer basic folder structure
    Set fsoDir = CreateObject("Scripting.FileSystemObject")
    If Not fsoDir.FolderExists(cProjects & strMfrCode) Then
        fsoDir.CreateFolder (cProjects & strMfrCode)
    End If
    If Not fsoDir.FolderExists(cProjects & strMfrCode & "\Approved")
Then
        fsoDir.CreateFolder (cProjects & strMfrCode & "\Approved")
    End If
    If Not fsoDir.FolderExists(cProjects & strMfrCode & "\Unapproved")
Then
        fsoDir.CreateFolder (cProjects & strMfrCode & "\Unapproved")
    End If
    If Not fsoDir.FolderExists(cProjects & strMfrCode & "\Post
Approval") Then
        fsoDir.CreateFolder (cProjects & strMfrCode & "\Post Approval")
    End If
    'Now create the new folder
    If Not fsoDir.FolderExists(cProjects & strMfrCode & "\TN" &
Format(vTNNum, "000000")) Then
        fsoDir.CreateFolder (cProjects & strMfrCode & "\TN" &
Format(vTNNum, "000000"))
    End If

    'Finally move all of the files from the standard application
directory
    'to the newly created folder.
    strMsgText = "Moving Project To Final Project Destination Folder"
    DoCmd.OpenForm "Status Display", , , , acFormReadOnly, acDialog,
strMsgText
    If fcnCopyFolders(cStdDir, cProjects & strMfrCode & "\TN" &
Format(vTNNum, "000000")) Then
        fcnMakeDestFolder = True
    Else
        fcnMakeDestFolder = False
    End If

ProcExit:
    If Not fsoDir Is Nothing Then
        Set fsoDir = Nothing
    End If
    Exit Function

ErrorHandler:
    MsgBox "The following error has occured:" & vbCrLf & _
        "Error Number: " & Err.Number & vbCrLf & _
        "Description: " & Err.Description & vbCrLf & _
        "Please contact the DEIMS system administrator with this
information.", vbOKOnly + vbCritical, _
        "Standard Application: Function Make Destination Folder"
    fcnMakeDestFolder = False
    GoTo ProcExit

End Function

'*****************
This is the function fcnCopyFolders

Public Function fcnCopyFolders(strFolderName As String, strStdDir As
String) As Boolean
On Error GoTo ErrorHandler

    'Declare Local Variables
    Dim fsoDir As Object, fsoSearchDir As Object
    Dim Folder As Object, SubFolders As Object, SubFolder As Object

    Set fsoDir = CreateObject("Scripting.FileSystemObject")
    Set Folder = fsoDir.GetFolder(strFolderName)
    Set SubFolders = Folder.SubFolders
    
    'Copy all of the subfolder objects to the standard directory
    If SubFolders.Count <> 0 Then
        For Each SubFolder In SubFolders
            fsoDir.CopyFile SubFolder.Path & "\*.*", strStdDir
        Next SubFolder
    End If

    'Copy all of the main folder objects to the standard directory
    fsoDir.CopyFile strFolderName & "\*.*", strStdDir

    fcnCopyFolders = True
    Exit Function

ErrorHandler:
    fcnCopyFolders = False

End Function 

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller
Sent: Thursday, August 18, 2005 2:02 PM
To: 'Access Developers discussion and problem solving'
Subject: [AccessD] Storing Files in Directories

The current client has distinct preferences about how files ought to be
stored. 

A client has 1:M projects.
A project has 1:M assessments.
An assessment concerns exactly one workstation.
The resulting document must come out reflecting all workstations
involved in said project for said client (this part is trivial).

The client app's native directory is c:\MyClient. The subdir for said
reports is c:\MyClient\reports.

The client wants me to create a dir for each project and then plant the
related documents in said project-subdir.

This says to me that the Client table contains a directory name, and
that the ClientProjects table also contains a directory name, and that
given project 12356 I concatenate the above two values, plus the unique
identifier, and create a file called "c:\MyClient\HerClient\Reports\" &
Unique_ID & ".doc" (the resultant docs are all Word files).

1. I have so far created the said doc from a template: no problems
there.
But I would like also to supply the concatenated filename so that a
simple click on the Save button causes the file to be saved. (I should
mention that the docs spit out by the Access app _always_ require
editing; else we would simply dump an Access report.)

Given that the client is CharlotteFoust and that her docs get sent to
c:\MyClient\HerClient\CharlotteFoust, then I want Word to realize that
the created document should be called
"c:\MyClient\HerClient\CharlotteFoust\" & Unique_ID & ".doc" -- and
placed in subdir (create if required) Project 20050818.

I don't want the user to have to name the file. I want that to have
already been done, so she can click Save after her edits and that's
that.

Had I been granted the discretion to design this particular model, I
would not have chosen this path. That however is not the issue. The
issue is that the client and her employees want to do it this way. 

Advice, guidance, assaults on the model, all gratefully accepted.


--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list