[AccessD] Storing Files in Directories

MartyConnelly martyconnelly at shaw.ca
Thu Aug 18 14:46:29 CDT 2005


I have done something similar for records management but I create the 
directory name structures from a table
easier to maintain.. One funny is trying to delete the upper root 
directory if created by the program
it may require a reboot to lose NFTS file handle of the root..

You may need this routine to check for illegal DOS filename characters
And perhaps change spaces to underscores.
If your directory filename string greater than 256, there is  trouble 
burning to Joliet CD-ROM format.

 Function NameFix(NameIn As String) As String
   Const ILLEGAL_CHARACTERS = "/\:*?<>|"""
   ' = /\:*?<>|"
   Dim i As Integer
   Dim iTmp As Integer
   'replaces illegal DOS filename character with an underscore
   NameFix = NameIn

   For i = 1 To Len(ILLEGAL_CHARACTERS)
      iTmp = InStr(1, NameFix, Mid$(ILLEGAL_CHARACTERS, i, 1))
      If iTmp > 0 Then
         Mid$(NameFix, iTmp, 1) = "_"
      End If
   Next
   'non ascii printing characters
  ' Just realized this code will also replace spaces with
  'underscores.
'to accept spaces, change
'>       If iTmp < 33 Or iTmp > 126 Then to
'>       If iTmp < 32 Or iTmp > 126 Then

   For i = 1 To Len(NameFix)
      iTmp = Asc(Mid$(NameFix, i, 1))
      If iTmp < 32 Or iTmp > 126 Then
         Mid$(NameFix, i, 1) = "_"
      End If
   Next
End Function
'============


This routine creates the directories and upper path structure if 
non-existant

'**************************************
' Name: CreateDirectoryStruct
' Description:Creates all non-existing folders in a path.
' Local or network UNC path.
'
' Inputs:CreateThisPath as string
'

'CreateDirectoryStruct("c:\temp\c\b\a")

 Sub CreateDirectoryStruct(CreateThisPath As String)

    'do initial check
    Dim ret As Boolean, temp$, ComputerName As String, IntoItCount As 
Integer, X%, _
              WakeString As String
    Dim MadeIt As Integer
    If Dir$(CreateThisPath, vbDirectory) <> "" Then Exit Sub
    'is this a network path?

    If Left$(CreateThisPath, 2) = "\\" Then ' this is a UNC NetworkPath
        'must extract the machine name first, th
        '     en get to the first folder
        IntoItCount = 3
        ComputerName = Mid$(CreateThisPath, IntoItCount, 
InStr(IntoItCount, _
                 CreateThisPath, "\") - IntoItCount)
        IntoItCount = IntoItCount + Len(ComputerName) + 1
        IntoItCount = InStr(IntoItCount, CreateThisPath, "\") + 1
        'temp = Mid$(CreateThisPath, IntoItCount
        '     , x)
    Else ' this is a regular path
        IntoItCount = 4
    End If

    WakeString = Left$(CreateThisPath, IntoItCount - 1)
    'start a loop through the CreateThisPath
    '     string

    Do
        X = InStr(IntoItCount, CreateThisPath, "\")


        If X <> 0 Then
            X = X - IntoItCount
            temp = Mid$(CreateThisPath, IntoItCount, X)
        Else
            temp = Mid$(CreateThisPath, IntoItCount)
        End If

        IntoItCount = IntoItCount + Len(temp) + 1
        temp = WakeString + temp
        'Create a directory if it doesn't alread
        '     y exist
        ret = (Dir$(temp, vbDirectory) <> "")


        If Not ret Then
            'ret& = CreateDirectory(temp, Security)
            MkDir temp
        End If

        IntoItCount = IntoItCount 'track where we are in the String
        WakeString = Left$(CreateThisPath, IntoItCount - 1)
    Loop While WakeString <> CreateThisPath

End Sub
Arthur Fuller wrote:

>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.
>
>
>  
>

-- 
Marty Connelly
Victoria, B.C.
Canada






More information about the AccessD mailing list