I'm baffled. On Form1, I have the following lines of code:
Form2 has three buttons (Yes, Yes to All, No) which set gbOverwrite or gbOverwriteOnce to true or false, depending on whether you want to overwrite this one file or All Files.
When the file(s) are not there, it runs through perfectly. When you select "Yes to All" (setting gbOverwrite to True), it runs through fine. But if you select No or Yes, the next iteration through is still on the same file, so you will never get past the first file. I think this has something to do with the modal form, but I can't see why it would reset the for...each loop to the first object in the collection.
If anyone has any ideas on this at all, let me know.
Kevin
"There are only three types of people in the world. Those who can count, and those who can't." - Warren Buffet
Code:
Private Sub Form_Activate()
Dim fso As New FileSystemObject
Dim fld As Folder
Dim fil As File
Set fld = fso.GetFolder("C:\Temp")
For Each fil In fld.Files
Me.Caption = fil.Name
DoEvents
If Not fso.FileExists("C:\Temp1\" & fil.Name) Or gbOverwrite Then
fil.Copy "C:\Temp1\" & fil.Name, gbOverwrite
Else
Form2.Caption = fil.Name
Form2.Show vbModal
If gbOverwrite Or gbOverwriteOnce Then fil.Copy "C:\Temp1\" & fil.Name, True
End If
DoEvents
Next
Unload Me
End Sub
When the file(s) are not there, it runs through perfectly. When you select "Yes to All" (setting gbOverwrite to True), it runs through fine. But if you select No or Yes, the next iteration through is still on the same file, so you will never get past the first file. I think this has something to do with the modal form, but I can't see why it would reset the for...each loop to the first object in the collection.
If anyone has any ideas on this at all, let me know.
Kevin
"There are only three types of people in the world. Those who can count, and those who can't." - Warren Buffet