Exiting a loop

  • Thread starter Thread starter OldEnough
  • Start date Start date
O

OldEnough

I have a small update program to transfer files from the server to laptops
for use outside the office. As long as the user keeps up with changes this is
usually a quick process. But sometimes the user doesn't update and the list
of files gets to be large. I need a way to exit the transfer process (a
cancel button) in the middle of the transfer.

I have a button on the initiating form that changes the value of a control
when selected. The loop is supposed to check the value of the control on each
iteration, but it doesn't work. Can someone suggest a better approach?

In outline the loop is

For I = 0 to N(umber of files)
If Me.txtCancel <>0 Then Exit Sub
'identify file source path and file name.
'identify target path and file name.
'test to see if directory exisits and make directory if not
copyfile sourcefile destinationfile
Next I

Thanks for looking at this
 
hi,

without testing it...:

Option Compare Database
Option Explicit

Private m_Cancel As Boolean

Private Sub cmdCancel_Click()

m_Cancel = True

End Sub

Private Sub cmdTransfer_Click()

Dim I As Long

m_Cancel = False
For I = 0 to N(umber of files)
DoEvents
If m_Cancel Then
Exit For
End If
' identify file source path and file name.
' identify target path and file name.
' test to see if directory exisits and make directory if not
' copyfile sourcefile destinationfile
Next I

End Sub



mfG
--> stefan <--
 
Back
Top