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
Bookmarks