Results 1 to 4 of 4
  1. #1
    JDPrestige is offline Novice
    Windows 7 Access 2003
    Join Date
    Nov 2010
    Posts
    3

    Loop Problem

    Hi All,

    I have a form "frmTest" & subform "subfrmTestDetail". The subform
    "subfrmTestDetail" displays the recordset. I have a cmd button on "frmTest"
    with the following code:

    Dim rst As DAO.Recordset
    Dim lngLoadLineID As Long



    Set rst = CurrentDb.OpenRecordset("SELECT [LoadLineID],[EntryDate],
    [DeliveryDate],[Yard],[JDNo],[Plant],[OrderID],[Client],[Street],[Suburb],
    [AllocationSuburbOrder],[AreaKlm],[Pallets],[TimberSisFlexi],[Brick],
    [BrickType],[UnderMin],[Tile],[Apex],[Ridge],[Spoon],[Qty],[Delivered],
    [PickupNumber],[DocketNo],[InterstateCarrierID],[TruckType],[Driver],[TruckNo]
    ,[Rego],[Mobile],[SpecialReq],[Suby],[MinQty],[Code],[PTonne],[LoadCost],
    [JDRate],[SubRate],[JDPayment],[SubPayment],[Balance],[ContractID],[Confirmed]
    ,[fosUserName],[AmountPaid1],[AmountPaid2],[AmountPaidBalance],[Credits],
    [OutstandingBalance],[DeliverySlot],[DeliveryMethod],[PickupFrom],
    [DeliveredTo],[DriverID],[DayApproved],[CheckerApproved],[ApprovedDate],
    [ApprovedBy],[WorkSortOrder],[PaymentCode],[PricePeriod],[Builder],[JobNo],
    [Invoiced],[Postcode],[LoadBoxNo],[Allocated],[Abbrev],[Basket],
    [SpecialComments],[SpecialComments2],[SpecialComments3],DriverNo,
    ConfirmedLoad,[CommentAdded],[ContactName],[ContactNumber] FROM
    qryContractAdBriMasonry " _
    & "WHERE (((qryContractAdbriMasonry.LoadLineID)=" & Forms!frmTest!
    subfrmTestDetail.Form.LoadLineID & "));", dbOpenDynaset, dbSeeChanges)


    With rst
    rst.MoveFirst

    Do Until rst.EOF
    .Edit


    lngLoadLineID = ![LoadLineID]
    ![JDRate] = DLookup("[JDRate]", "qryContractRatesAdbri1", "[code]
    = " & Chr(34) & Forms!frmTest!subfrmTestDetail.Form.Code & Chr(34))
    ![SubRate] = DLookup("[SubyRate]", "qryContractRatesAdbri1", "
    [code]= " & Chr(34) & Forms!frmTest!subfrmTestDetail.Form.Code & Chr(34))
    !MinQty = 3
    !JDPayment = !JDRate * !MinQty
    !SubPayment = !SubRate * !MinQty
    !Balance = !JDPayment - !SubPayment
    .Update

    rst.MoveNext
    If rst.EOF Then
    Exit Do
    End If

    Loop

    End With



    Forms!frmTest!subfrmTestDetail.Requery

    '------------------------------------------ end code ---------------------

    The idea is for the code to loop all records displayed in subform & update.
    It only updates the very first record & does not loop the entire recordset.
    Can anyone see where i've gone wrong & why it isn't looping all records?

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    you recordset rst has only one row because you have the condition:

    WHERE (((qryContractAdbriMasonry.LoadLineID)=" & Forms!frmTest!
    subfrmTestDetail.Form.LoadLineID & "));",

    the LoadLineID is the value in current row of the subform, so your code only update this row in the table.

    if you want to update the whole table, just remove the where clause.

  3. #3
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    - or - approach it as a database task rather than a programmatic task. By that I mean - make & trigger an UpdateQuery rather than via a loop method.

  4. #4
    JDPrestige is offline Novice
    Windows 7 Access 2003
    Join Date
    Nov 2010
    Posts
    3
    OK, i've removed the WHERE clause but the DLOOKUP doesn't fire correctly. It appears that whatever record has focus the DLOOKUP looks up that particular value & then updates all the rows in the recordset with the SAME value. I don't get this!! Am i missing something?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Do While loop
    By jgelpi16 in forum Programming
    Replies: 7
    Last Post: 07-23-2010, 08:21 AM
  2. VBA Loop
    By DreamOn in forum Programming
    Replies: 4
    Last Post: 06-25-2010, 03:35 AM
  3. Replies: 9
    Last Post: 04-28-2010, 11:20 AM
  4. For Each LOOP statement
    By zambam737 in forum Programming
    Replies: 3
    Last Post: 10-26-2009, 09:59 PM
  5. concatenate string using loop
    By nengster in forum Programming
    Replies: 0
    Last Post: 02-23-2009, 08:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums