Solved

If statement causes for next loop to exit

Posted on 2014-03-20
4
120 Views
Last Modified: 2014-08-25
Hello,

I have a for next loop interating over a collection of dataset rows,

I want to insert a couple of if statements to populate a couple of cells in the rows but I'm finding as soon as the first if statement is processed the for next loop is exited.

Am I missing something?

Thanks
0
Comment
Question by:Petermcg001
  • 2
4 Comments
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39942416
Probably a problem with your structure, if you show the code we can help.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39942463
which programming language exactly?
it must be an explicit "code" in your code to "break" to "exit" the loop, please post the relevant part of the code
0
 
LVL 1

Author Comment

by:Petermcg001
ID: 39942504
Thanks for looking at this,

My vb.net code is:-
For Each DeliveryTicketRow As dsDeliveryTickets.UnprintedTicketsRow In DsDeliveryTickets.UnprintedTickets
            AccountsTableAdapter.FillBy(DsAccounts.Accounts, DeliveryTicketRow.Account)
            Account = DsAccounts.Accounts(0)
            With DeliveryTicketRow
                .AccountAddress1 = Account.AddressLine1
                .AccountAddress2 = Account.AddressLine2
                .AccountAddress3 = Account.AddressLine3
                .AccountTown = Account.AddressLine4
                .AccountName = Account.CustomerAccountName
                .AccountPostcode = Account.PostCode
                .AccountTelephoneNumber = Account.TelephoneNumber
                If .StatusFlag = "U" Then .UrgentText = "Urgent"


                If .LineNote = "F" Then .FillText = "Fill"


            End With

        Next

Open in new window


As soon as the first if is processed the loop exits.
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39949824
the code as such does not show anything that shall raise this issue.
so, either you have some (unhandled) error somewhere, OR it's the WITH statement structure which might give you that issue.
please try to run the code without the WITH, like this
For Each DeliveryTicketRow As dsDeliveryTickets.UnprintedTicketsRow In DsDeliveryTickets.UnprintedTickets
            AccountsTableAdapter.FillBy(DsAccounts.Accounts, DeliveryTicketRow.Account)
            Account = DsAccounts.Accounts(0)
            
                DeliveryTicketRow.AccountAddress1 = Account.AddressLine1
                DeliveryTicketRow.AccountAddress2 = Account.AddressLine2
                DeliveryTicketRow.AccountAddress3 = Account.AddressLine3
                DeliveryTicketRow.AccountTown = Account.AddressLine4
                DeliveryTicketRow.AccountName = Account.CustomerAccountName
                DeliveryTicketRow.AccountPostcode = Account.PostCode
                DeliveryTicketRow.AccountTelephoneNumber = Account.TelephoneNumber
                If DeliveryTicketRow.StatusFlag = "U" Then DeliveryTicketRow.UrgentText = "Urgent"


                If DeliveryTicketRow.LineNote = "F" Then DeliveryTicketRow.FillText = "Fill"

        Next

Open in new window

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question