Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Star Lounger
    Join Date
    Oct 2002
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    creating files and folders based on data (2002)

    Is it possible to us vb script to make folders and files based on data from a record?
    Whats the name of the command i shoud research if so?
    Thanks
    Adrian

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: creating files and folders based on data (2002)

    You can use either the "classic" Basic instructions or Scripting to create folders and plain text files. To create other kinds of files, you must use the appropriate application.

    "Classic" instructions:
    MkDir "foldername" creates a new folder in the current directory. Use ChDrive and ChDir to navigate to the correct folder first. Type any of these instructions in a module or in the Immediate window, then press F1 to get help.

    Scripting:
    Set a reference to Microsoft Scripting Runtime (Tools | References...)

    Dim fso As New Scripting.FileSystemObject
    Dim fld As Scripting.Folder
    Set fld = fso.CreateFolder("C:AccessTest")
    fld.CreateTextFile("Notes.txt")
    Set fld = Nothing
    Set fso = Nothing

    Look up FileSystemObject in the online help index, or in the Object Browser.

    To create other files than text files, either export an Access object (DoCmd.OutputTo, DoCmd.TransferSpreadsheet etc.) or use Automation to control the associated application.

  3. #3
    Star Lounger
    Join Date
    Oct 2002
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: creating files and folders based on data (2002)

    do you think it will work making changes to an ftp site mapped as a network drive?
    Adrian

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: creating files and folders based on data (2002)

    No idea, sorry. Perhaps others have experience in this area.

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: creating files and folders based on data (2002)

    I doubt that you're going to be able to create folders on an ftp site like that, but it may depend on the user permissions granted to the network user, not on anything in Access. If you're really talking about a vb script rather than VBA, you need to make that clear, since the two are not quite the same thing.
    Charlotte

  6. #6
    Star Lounger
    Join Date
    Oct 2002
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: creating files and folders based on data (2002)

    Ive worked it out.
    Thanks guys!
    Adrian

  7. #7
    Star Lounger
    Join Date
    Oct 2002
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: creating files and folders based on data (2002)

    The table i am getting information from has images linked to it as one of the fields (as ole links) is there any way i can write the filename of the image (without directory etc.) to the file ive made using the fso?
    Thanks
    Adrian.

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: creating files and folders based on data (2002)

    You can find a function that retrieves the full path of a linked OLE object in ACC2000: How to Retrieve the Path for Linked OLE Objects. Here is a modified version that retrieves only the file name, without the path.

    Function GetLinkedPath(objOLE As Variant) As Variant
    Dim strChunk As String
    Dim pathStart As Long
    Dim pathEnd As Long
    Dim path As String
    If Not IsNull(objOLE) Then
    ' Convert string to Unicode.
    strChunk = StrConv(objOLE, vbUnicode)
    pathStart = InStr(1, strChunk, ":", 1) - 1

    ' If mapped drive path not found, try UNC path.
    If pathStart <= 0 Then pathStart = InStr(1, strChunk, "", 1)

    ' If either drive letter path or UNC path found, determine
    ' the length of the path by searching for the first null
    ' character Chr(0) after the path was found.
    If pathStart > 0 Then
    pathEnd = InStr(pathStart, strChunk, Chr(0), 1)
    pathStart = InStrRev(strChunk, "", pathEnd) + 1
    path = Mid(strChunk, pathStart, pathEnd - pathStart)
    GetLinkedPath = path
    Exit Function
    End If
    Else
    GetLinkedPath = Null
    End If
    End Function

    (Since you're a regular visitor to this forum, I suppose you've read all the warnings against storing images in an Access database.)

  9. #9
    Star Lounger
    Join Date
    Oct 2002
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: creating files and folders based on data (2002)

    Thanks... ill try that.

    Just wondering... you warned of the perils of storing images in dbs:
    Are there similar problems for linking?

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: creating files and folders based on data (2002)

    >> Are there similar problems for linking?

    If I remember correctly, Access 97 databases tended to bloat even with linked images, but Access 2000/2002 seems to handle them more efficiently, so perhaps there is no objection against them.

  11. #11
    Star Lounger
    Join Date
    Oct 2002
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: creating files and folders based on data (2002)

    I think its starting to bloat slightly, but i should be able to deal with it.

    Another Q if you dont mind.
    Im writing lines to a file using .WriteLine of the fso.
    How can i get it to write one line for one field of every record in the db?

    I figure i have to do a For Each loop... but how do i tell it to do each record in the table?
    Thanks HEAPS!
    Adrian

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: creating files and folders based on data (2002)

    Say that you have a recordset rst that you have opened in code.
    You have also declared a variable i of type Integer

    Do While Not rst.EOF
    For i = 0 To rst.Fields.Count - 1
    ' Write out rst.Fields(i) here
    Next i
    rst.MoveNext
    Loop

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: creating files and folders based on data (2002)

    I think I have misread your question. I thought that "write one line for one field of every record" meant that you wanted to write a separate line for each field. Apparently, you only want to save the ID field. If that is correct, the code becomes

    Do While Not rst.EOF
    indexf.WriteLine " <td>[img][/img]</td>"
    rst.MoveNext
    Loop

    where rst is the recordset you have opened.

  14. #14
    Star Lounger
    Join Date
    Oct 2002
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: creating files and folders based on data (2002)

    reguarding the repeat loop, i cant get the syntax right
    the line i want to repeat is:

    indexf.WriteLine " <td>[img][/img]</td>"
    im not sure what you mean by:
    >> ' Write out rst.Fields(i) here

    Actually i think my problem is not knowing how to open the record set in code.

  15. #15
    Star Lounger
    Join Date
    Oct 2002
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: creating files and folders based on data (2002)

    I think my problem is that i dont know how to open the recordset in code.
    Is a table a record set?
    I guessed it was
    dim rst as recordset
    and then
    set rst = Tables!FWKS
    But im just stabbing around in the dark.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •