Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2004
    Posts
    277

    Unanswered: Create New Folder

    how can I create a new folder in vba? also how can I check to see if the folder exists?

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    What version of Access? I believe you get the FileScriptingObject facility in 2k+
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    This works in 97:

    MkDir() will create a folder for you.

    Then to see if a folder exists use the Dir() function along with the file attributes to look for the folder:

    Dir("C:\Program Files",vbDirectory)

    Will look for a folder named Program Files and return Program Files if it is found.

  4. #4
    Join Date
    Dec 2004
    Posts
    277
    the 2k version.... but is there a way of checking to see if a folder exists first... because with everything it should be keeping a backup copy of different reports based off the reference number. For example, a pickupsheet, a bill of lading, checks received, and proofs of delivery.

    So if the folder exists then save report, if folder does not exist then create folder and save report. Please help need done quick.....

  5. #5
    Join Date
    Dec 2004
    Posts
    277
    but i need for it to check if the folder exists in the background...not for the user looking for it...

  6. #6
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    Maybe I wasn't very clear... To see if a folder exists call this function:

    Code:
    Public Function FolderExists(strFolderName As String) As Boolean
    
        Dim strFolder As String
        
        strFolder = Dir(strFolderName, vbDirectory)
        If strFolder = "" Then
            FolderExists = False
        Else
            FolderExists = True
        End If
    
    End Function

  7. #7
    Join Date
    Dec 2004
    Posts
    277
    why does it tell me that the argument is not optional?

  8. #8
    Join Date
    Dec 2004
    Posts
    277

    this is what it looks like so far.....

    Option Compare Database
    Public Function FolderExists(strFolderName As String) As Boolean

    Dim strFolder As String
    Dim quote As String
    quote = InputBox("Please enter quote #", "Enter Quote #")
    strFolderName = "x:\Quotes\" + quote
    strFolder = Dir(strFolderName, vbDirectory)
    If strFolder = "" Then
    FolderExists = False
    Else
    FolderExists = True
    End If

    End Function



    Private Sub Command8_Click()
    If FolderExists = False Then
    MkDir ("x:\Quotes\" + quote)
    DoCmd.OutputTo acOutputReport, "quote1", acFormatRTF, "x:\Quotes\" + quote + ".rtf"
    Else
    DoCmd.OutputTo acOutputReport, "quote1", acFormatRTF, "x:\Quotes\" + quote + ".rtf"
    End If
    End Sub

  9. #9
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    Minor changes:

    Code:
    Public Function FolderExists(strFolderName As String) As Boolean
    
         Dim strFolder As String
    
         strFolder = Dir(strFolderName, vbDirectory)
         If strFolder = "" Then
              FolderExists = False
         Else
              FolderExists = True
         End If
    
    End Function
    Leave the FolderExists function alone, call it from the OnClick event like:

    Code:
    Private Sub Command8_Click()
         Dim strFolderName as string
         Dim quote As String
    
         quote = InputBox("Please enter quote #", "Enter Quote #")
         strFolderName = "x:\Quotes\" & quote
    
         If FolderExists(strFolderName) = False Then
              MkDir (strFolderName)
         End If
    
         'Since you always want to create the report then move this outside the If-Then
         DoCmd.OutputTo acOutputReport, "quote1", acFormatRTF, strFolderName & quote & ".rtf"
    
    End Sub

  10. #10
    Join Date
    Dec 2004
    Posts
    277
    thanks... i'll have a drink for ya on New Years

Posting Permissions

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