Results 1 to 6 of 6

Thread: Do While Loop

  1. #1
    Join Date
    May 2003
    Location
    UK
    Posts
    233

    Unanswered: Do While Loop

    The first part of this code works ok. When the net + vat = gross it will Call the function. It is second part where I want the MsgBox to be displayed.

    Code:
    Do
    Do While Net + VAT = Gross
    Call Batch_Update

    'MsgBox "The Net and VAT Do Not Equal The Gross!"
    'txtNet.SetFocus

    If Net <> VAT = Gross Then
    MsgBox "The Net and VAT Do Not Equal The Gross!"
    txtNet.SetFocus
    End If

    Exit Do ' Exit inner loop.

    Loop
    Loop Until Net + VAT = Gross Or Net + VAT <> Gross

  2. #2
    Join Date
    Apr 2004
    Location
    metro Detroit
    Posts
    634
    try
    If Net + VAT <> Gross Then

    rather than
    If Net <> VAT = Gross Then

  3. #3
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Code:
    Do
    ......
    Loop Until Net + VAT = Gross Or Net + VAT <> Gross

    Also, isn't this an endless loop? Doesn't Net + VAT pretty much always have to be either <> Gross or = Gross?
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    Join Date
    Nov 2002
    Posts
    272
    Quote Originally Posted by Missinglinq
    Loop Until Net + VAT = Gross Or Net + VAT <> Gross

    Also, isn't this an endless loop? Doesn't Net + VAT pretty much always have to be either <> Gross or = Gross?
    It would be if it were a While instead of an Until. This way, it will always exit the loop after one pass.
    But you're right, it doesn't make sense.

  5. #5
    Join Date
    May 2003
    Location
    UK
    Posts
    233
    Yes it will always exit the loop after one pass. However, it only seems to read the first part of the code. When the Net and Vat do not equal the gross, nothing happens. what I want is for the message to be displayed.

    Sorry, I am struggling with this a bit!! All help really appreciated.

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    If you only want a single pass then why are you using a loop?
    Code:
    If NET + VAT = Gross Then
     MsgBox "Oooh!"
    Else
     MsgBox "Ahhh!"
    End If
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •