By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,282 Members | 1,518 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,282 IT Pros & Developers. It's quick & easy.

Stopping a For Next Loop until a value is return from another form

P: 3

I am pretty new to and am having trouble figuring out how to do this.

I have an app that copies data from one datasource to another.

I have it set to run through a for loop for each row in SourceDataTable.

for each row i get the a value that is not an ID and I have a funciton that compares this to a column in the Destination, and i recieve the ID back if it exits and nothing if it doesn't. This work fine the next part I am having trouble with.

I then have an IF statement that test if the ID is returned or not then chooses whether to run the Insert if it does exist or If the ID doesn't exist i want to open up a form where i can choose (and return) the ID i want to use (i know how to set all this up)

the problem i am having is that i the for loop that is transferring data from the source to the destination keeps going.

here is the for loop i am using, i just need to know how to stop the loop from running while i am retrieving strID from a new form. i have put this bit in red

Expand|Select|Wrap|Line Numbers
  2. For i = 0 To dbDataTable.Rows.Count - 1
  4. 'get the value for the ID to compare
  5. str1 = dbDataTable.Rows(i)(0).ToString
  6. str1 = Replace(str1, "'", "")
  8. 'compare the source ID to the destination ID column to see if it is to be update or insert
  9. strID = Compares.ReturnDestinationID(dbDestinationDataset, str1)
  11. If strID = "" Then
  13. 'open form for retrieving ID to use for insert
  14. strID = Value recieved back from other form
  16. 'run insert sub using the new strID
  17. Inserts.InsertDataRowToDestination(dbDataTable.Rows(i), strID)
  19. Else
  21. 'this is a sub I have created to insert the data row to the destination table
  22. Inserts.InsertDataRowToDestination(dbDataTable.Rows(i), strID) 
  24. End If
  26. Next
any direction will be very greatly appreciated
Jul 25 '08 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 979
Hi pfildes,

You can use
Expand|Select|Wrap|Line Numbers
  2. Exit For
to stop the loop.

Hope this helps,

Dr B
Jul 25 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.