Results 1 to 4 of 4

Thread: Program Freeze :-(

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Posts
    89

    Question Program Freeze :-(

    Hello All,

    When I use the following code my program freezes and I end up having to terminate vb, any ideas?

    VB Code:
    1. Private Sub Form_Load()
    2.     dcCars.Refresh
    3.     'adds cars to list box
    4.     While Not dcCars.Recordset.EOF
    5.         'Only displays cars which aren't on hire
    6.         If dcCars.Recordset("OnHire") = "No" Then
    7.             lstCars.AddItem (dcCars.Recordset("Reg"))
    8.             dcCars.Recordset.MoveNext
    9.         End If
    10.     Wend
    11. End Sub


    Thanks!

  2. #2
    Fanatic Member
    Join Date
    Feb 2002
    Location
    SE England
    Posts
    732
    Move the MOVENEXT to outside the if block...


    Code:
    Private Sub Form_Load()
        dcCars.Refresh
        'adds cars to list box
        While Not dcCars.Recordset.EOF
            'Only displays cars which aren't on hire
            If dcCars.Recordset("OnHire") = "No" Then
                lstCars.AddItem (dcCars.Recordset("Reg"))
                
            End If
    
          dcCars.Recordset.MoveNext
    
        Wend
    End Sub
    Leather Face is comin...


    MCSD

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    move dcCars.Recordset.MoveNext to after the End If
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Posts
    89
    Thanks alot, I would normally have seen that, I guess you start to miss things after 8 hours or programming :-)


    Thanks again!

Posting Permissions

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



Click Here to Expand Forum to Full Width