Results 1 to 3 of 3

Thread: Do Until Loop?

  1. #1
    Join Date
    May 2005
    Posts
    150

    Unanswered: Do Until Loop?

    Code:
    '--- Special Services
    Dim strSpecialInfo As String
    
    Dim rstSServ As ADODB.Recordset
    Dim sqlSServ As String
    Dim SService As String
    
    Set rstSServ = New ADODB.Recordset
    
    sqlSServ = "SELECT tblSServices.[Reference#], tblSServices.srvID, tblSServices.srvName"
    sqlSServ = sqlSServ & " FROM tblSServices"
    sqlSServ = sqlSServ & " WHERE tblSServices.[Reference#]=" & strgRef & ";"
    
    With rstSServ
    .CursorLocation = adUseClient
    .CursorType = adOpenDynamic
    .LockType = adLockBatchOptimistic
    .Open sqlSServ, CurrentProject.Connection
    
    strSpecialInfo = ""
    
    Do Until .EOF = False
        If .BOF = False Then
        .MoveFirst
        End If
    
    SService = Nz(.Fields("srvName").Value, "")
    
    'MsgBox SService
    
    If SService = "Notify" Then
    SService = "Please Notify Consignee prior to delivery"
    End If
    
    If SService = "Guaranteed Delivery" Then
    SService = "Guaranteed Delivery. Please Note Must Deliver By Time"
    End If
    
    strSpecialInfo = strSpecialInfo & SService & vbCrLf
    
    MsgBox strSpecialInfo
    .MoveNext
    Loop
    
    .Close
    End With
    
    Set rstSServ = Nothing
    Keeps returning the same value and the loop never seems to end

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Right now you're running into problems because of this:

    If .BOF = False Then
    .MoveFirst
    End If

    You will ALWAYS be processing the first record according to that statement...

    Try something more like this:

    Code:
    With rstSServ
       .CursorLocation = adUseClient
       .CursorType = adOpenDynamic
       .LockType = adLockBatchOptimistic
       .Open sqlSServ, CurrentProject.Connection
    
       .MoveFirst    'Probably not necessary, good practice more than anything
    
       While Not .Eof
          'Your Code
          .MoveNext
       Wend
    End With
    Last edited by Teddy; 11-18-05 at 11:28.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    May 2005
    Posts
    150
    thank you sir... that worked perfectly

Posting Permissions

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