troubleshooting Question

Runtime error '424': Object Required

Avatar of NUPE2006
NUPE2006 asked on
Visual Basic Classic
10 Comments1 Solution2125 ViewsLast Modified:
Greetings,

When I run my program I get error 424 object required even though it is declared in the program already. I've attaced the code below, could someone help me fix this error? The error occurs in the Clean Files sub.

Thanks
Private Sub cmdYesD_Click()
    Dim fso As New FileSystemObject
    Dim File1 As File
    Dim Folder1 As Folder
    Dim FileCollection As Folder
    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
        'DoEvents
        'Do
        'DoEvents
        'Me.Refresh
                'If DateDiff("d", FileDateTime(File1), Now) >= intDays2 Then
                    'fso.DeleteFile (File1)
                    'intDelete = intDelete + 1
                'End If
        'Loop
    'Next
    Me.Refresh
    'Next
        'Call Cleanfolders
        For Each Folder1 In FileCollection.SubFolders
'Move Progressbar
            ProcessedFiles = ProcessedFiles + 1
            Me.ProgressBar1.Value = ProcessedFiles
        'DoEvents
        Do
        DoEvents
        'Me.Refresh
                If DateDiff("d", Folder1.DateCreated, Now) >= intDays2 Then
                    fso.DeleteFolder (Folder1)
                    intDeleteFolder = intDeleteFolder + 1
                End If
        Loop
    Next
            Me.Hide
            frmFFMMain.Show
  MsgBox "Complete.  Deleted: " & vbCrLf & intDelete & " files and " & vbCrLf & intDeleteFolders & " Folders"
        Else
        Call RegionError
    End If
            Me.Hide
            frmFFMMain.Show
End Sub
 
________________________________________________________________________
 
Private Sub Cleanfiles()
    For Each File1 In FileCollection.Files
'Move Progressbar
            ProcessedFiles = ProcessedFiles + 1
            Me.ProgressBar1.Value = ProcessedFiles
        Do Until TotalFiles
                If DateDiff("d", FileDateTime(File1), Now) >= intDays2 Then
                    fso.DeleteFile (File1)
                    intDelete = intDelete + 1
                End If
        Loop
Next
End Sub
________________________________________________________________________
 
Public Sub 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
End Sub
________________________________________________________________________
 
Public Sub RegionError()
    'If fso.FolderExists("Z:\" & strRegion2 & "\Customer\Output") = False Then
                    MsgBox "Error: Region not Found"
                        Me.Hide
                        frmFFMMain.Show
                'End If
End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 10 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros