NUPE2006
asked on
Program Bar dosen't function and Program freezes
When I run the code below it freezes up and the progress bar dosen't function. Can someone let me know where I went wrong, what I did wrong, and methods to fix the problems? Thanks and I appreciate it.
Private Sub cmdYesD_Click()
Dim File1 As File
Dim Folder1 As Folder
Dim FileCollection As Folder
Dim fso As New FileSystemObject
Dim strRegion2 As String
Dim intDays2 As Integer
Dim intDelete As Integer
Dim intDeleteFolder As Integer
Dim TotalFiles As Integer
Dim ProcessedFiles As Integer
strRegion2 = Me.txtRegionConf.Text
intDays2 = Me.txtInputDays.Text
ProcessedFiles = 0
'intDelete = 0
'intDeleteFolder = 0
'Deletes Files
If fso.FolderExists("Z:\" & strRegion2 & "\Customer\Output") Then
Set FileCollection = fso.GetFolder("Z:\" & strRegion2 & "\Customer\Output")
'Set progress bar maximum to files + folders
TotalFiles = FileCollection.Files.Count + FileCollection.SubFolders.Count
Me.ProgressBar1.Max = TotalFiles
'search for and delete files
'Call Cleanfiles
For Each File1 In FileCollection.Files
'Move Progressbar
ProcessedFiles = ProcessedFiles + 1
Me.ProgressBar1.Value = ProcessedFiles
Do
If DateDiff("d", FileDateTime(File1), Now) >= intDays2 Then
fso.DeleteFile (File1)
intDelete = intDelete + 1
End If
Loop
Next
'Next
'Call Cleanfolders
For Each Folder1 In FileCollection.SubFolders
'Move Progressbar
ProcessedFiles = ProcessedFiles + 1
Me.ProgressBar1.Value = ProcessedFiles
Do Until TotalFiles
If DateDiff("d", Folder1.DateCreated, Now) >= intDays2 Then
fso.DeleteFolder (Folder1)
intDeleteFolder = intDeleteFolder + 1
End If
Loop
Next
MsgBox "Complete. Deleted: " & vbCrLf & intDelete & " files and " & vbCrLf & intDeleteFolders & " Folders"
Else
Call RegionError
End If
Me.Hide
frmFFMMain.Show
End Sub
________________________________________________________________________
Public Function RegionError()
'If fso.FolderExists("Z:\" & strRegion2 & "\Customer\Output") = False Then
MsgBox "Error: Region not Found"
Me.Hide
frmFFMMain.Show
'End If
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
NUPE2006,
There is no space. Simply "DoEvents" , it is not a loop and is simply a keyword which allows the processor to process other events.
TimCottee
There is no space. Simply "DoEvents" , it is not a loop and is simply a keyword which allows the processor to process other events.
TimCottee
ASKER
Oh...I learn something new everyday.
Thanks you very much for sharing your knowledge.
-Gibran
Thanks you very much for sharing your knowledge.
-Gibran
ASKER
Thanks for taking the time to explain it to me.
ASKER