+ Reply to Thread
Results 1 to 2 of 2

probems creating folders: "......... folders already existed"

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    probems creating folders: "......... folders already existed"

    Hello everyone. I am trying to add onto to some code that I developed some time ago. The user is promtped from a mesage box to enter a date, that then passes through the variable called fDate. I then create a series of folders based on fDate. For example if the user enters the date of 30-jun-2010 a folder called 30-jun-2010_157 is created. What i would like to do is also create folders for the two months prior to fDate, that would be 30-apr-2010_157 and 31-may-2010_157 using June as an example. And so I coded that in however when I run the code the "computer" tells me that the two previous months to this date through "already existed". I suspect the problems lies in my use of the variable ErrBuf ?
      Dim fDate          As String
        Dim fPath            As String
        Dim fDatePrevious1   As String
        Dim fDatePrevious2   As String
        Dim fDatePrevious3   As String
        Dim fPriorDate1      As String
        Dim fPriorDate2      As String
        Dim fPriorDate3      As String
        
        Sub CreateFolder()
    '***********************************************************************
    'CreateFolder() macro creates the folders for the 157 Automation process.
    '***********************************************************************
    
        Dim Fldr   As String
        Dim ErrBuf As String
    
        fDate = Application.InputBox("Enter a date in the format shown:", "Date to add...", Format(Date, "DD-MMM-YYYY"))
        If fDate = "False" Then Exit Sub
        
        fDatePrevious1 = DateSerial(Year(fDate), Month(fDate), 0)
        fPriorDate1 = Format(fDatePrevious1, "DD-MMM-YYYY")
        
        fDatePrevious2 = DateSerial(Year(fDate), Month(fDate) - 1, 0)
        fPriorDate2 = Format(fDatePrevious2, "DD-MMM-YYYY")
        
        fDatePrevious3 = DateSerial(Year(fDate), Month(fDate) - 2, 0)
        fPriorDate3 = Format(fDatePrevious3, "DD-MMM-YYYY")
           
        '**********************************************************************
        'Formula used to calculate the prior quarter.
        '**********************************************************************
    
        fPath = "L:\"
    
        On Error GoTo ErrorHandler
            
            Fldr = fPath & fDate & "_157"
            MkDir Fldr
            
            Fldr = fPath & fDatePrevious1 & "_157"
            MkDir Fldr
            
            Fldr = fPath & fDatePrevious2 & "_157"
            MkDir Fldr
            
                
        If Len(ErrBuf) > 0 Then MsgBox "The following folders already existed:" & vbLf & vbLf & ErrBuf
        
        Exit Sub
        
    ErrorHandler:
        ErrBuf = ErrBuf & vbLf & Fldr
        Resume Next
        
    End Sub
    Last edited by AnthonyWB; 08-12-2010 at 03:04 PM.

  2. #2
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: probems creating folders: "......... folders already existed"

    I solved it. Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1