Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2001
    Posts
    175

    Unanswered: Loop not working

    My loop is not working. It is not going to the next record. It's looping only on the first record. What am I doing wrong?????

    It is based on info entered on a form (ConsolNumber)/subform(BillsofLading)

    Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
    Dim x As Currency
    Dim xx As Currency
    Dim oceandb As Database
    Dim oceanrst As DAO.Recordset
    Dim endoffile As Boolean
    Dim varx As String
    Dim boltype As String
    Dim vary As Variant

    endoffile = False
    Set oceandb = CurrentDb()
    Set oceanrst = oceandb.OpenRecordset("qryBillsofLading")

    With oceanrst
    Do While endoffile = False
    varx = [Forms]![ConsolNumber]!ConsolNumber
    boltype = [Forms]![ConsolNumber]![BillsofLading subform]!TypeofBL
    vary = [Forms]![ConsolNumber]![BillsofLading subform]!BillsofLading

    If boltype = "Collect" Then
    If OceanFreight <> 0 Then
    OceanFreight.Visible = True
    Label150.Visible = True
    Text102.Visible = False
    x = OceanFreight
    Else: OceanFreight.Visible = False
    Label150.Visible = False
    Text102.Visible = False
    End If
    If BLFee <> 0 Then
    BLFee.Visible = True
    Label151.Visible = True
    Text103.Visible = False
    x = x + BLFee
    Else: BLFee.Visible = False
    Label151.Visible = False
    Text103.Visible = False
    End If
    ElseIf boltype = "Prepaid" Then
    If OceanFreight <> 0 Then
    Label150.Visible = True
    Text102.Visible = True
    OceanFreight.Visible = False
    xx = Text102
    Else: Label150.Visible = False
    Text102.Visible = False
    OceanFreight.Visible = False
    End If
    If BLFee <> 0 Then
    Label151.Visible = True
    Text103.Visible = True
    BLFee.Visible = False
    xx = xx + Text103
    Else: Label151.Visible = False
    Text103.Visible = False
    BLFee.Visible = False
    End If

    Me!Text109 = xx
    Me!Text96 = x
    End If
    .MoveNext
    endoffile = (.EOF = True)
    Loop
    End With


    HELP NEEDED URGENTLY!!!!

  2. #2
    Join Date
    May 2002
    Posts
    395

    Do Until Loop

    Why don't you try Do Until oceanrst.EOF

    Set ...
    Do Until oceanrst.EOF
    .
    .
    oceanrst.MoveNext
    Loop

    Good Luck!

  3. #3
    Join Date
    Sep 2001
    Posts
    175
    Loop still not working.

    Any other suggestions

  4. #4
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820
    i'm not certain about this but

    endoffile = (.EOF = True)

    doesn't this set the end of file marker to true? ie after 1 pass the loop ends, try removing it completly or changing it to

    endoffile = (.EOF And True)
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

  5. #5
    Join Date
    Oct 2002
    Location
    Rochester, NY
    Posts
    84
    Originally posted by m.timoney
    i'm not certain about this but

    endoffile = (.EOF = True)

    doesn't this set the end of file marker to true? ie after 1 pass the loop ends, try removing it completly or changing it to

    endoffile = (.EOF And True)
    I would agree. Why even bother using the endoffile variable? Try making the change m.timoney suggested at first and remove the assignment of endoffile at the end of your loop.

    Do until oceanrst.EOF (you could also use Do While Not oceanrst.EOF)

    ...
    oceanrst.movenext

    Loop

    You shouldn't need the variable endoffile because the recordset property EOF will automatically update to true when you reach the last record. If you must use it, try setting like this:

    endoffile = oceanrst.EOF
    Regards,
    Terry

Posting Permissions

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