Results 1 to 15 of 15
  1. #1
    jerem is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    88

    Loop through continuous form recordset crash

    Hi,




    My application crashes when trying to change the value of a text box in a continuous form. Here is the code:
    Code:
    Private Sub cboPoCurrency_AfterUpdate()
    On Error GoTo ErrHandler
        Dim rst As Recordset
        With Me.sbfProductDetails.Form
            Set rst = .Recordset
            rst.MoveFirst
            Do While Not rst.EOF
                .txtUnitCost = 1
                rst.MoveNext
            Loop
        End With
        Set rst = Nothing
    ExitSub:
        Exit Sub
    ErrHandler:
        Call ErrorAlert
        Resume ExitSub
    End Sub

    If I replace .txtUnitCost by MsgBox .txtUnitCost, it loops correctly through each record and returns the value. But if I try to change the value as shown in above code, MS Access crashes!
    (This is a desktop application with tables linked to SP lists - not a web app)

    Cross:
    http://www.access-programmers.co.uk/...41#post1359341
    http://www.utteraccess.com/forum/Loo...l#entry2472070

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    I presume the textbox is bound to field.

    Try using RecordsetClone and reference the fieldname:
    Code:
    Private Sub cboPoCurrency_AfterUpdate()
    On Error GoTo ErrHandler
        With Me.sbfProductDetails.Form.RecordsetClone
            .MoveFirst
            Do While Not .EOF
                !fieldname = 1
                .MoveNext
            Loop
        End With
    ExitSub:
        Exit Sub
    ErrHandler:
        Call ErrorAlert
        Resume ExitSub
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    jerem is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    88
    Well, Access is not crashing anymore but now I get the following error: Update or CancelUpdate without AddNew or Edit

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Okay,

    .AddNew
    !fieldname = 1
    .Update


    Actually, Recordset will work as well as RecordsetClone. The difference is with RecordsetClone will not see focus move record to record.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    jerem is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    88
    I get the error: "Overflow"
    I can upload a light version of the DB if necessary

  6. #6
    jerem is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    88
    Ok, the overflow was a side error. I got it to work in a local table environment. But back in the Sharepoint linked table environment and I modify one of the records, I get an error that says: Could not update; currently locked
    So basically I get the same issue as with an UPDATE query...

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Sorry, no experience with SharePoint. Maybe cannot be done.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    This sounds like a lot of fun. I read one of the other threads. Maybe you can use recordset clone to update all of the records except the current. Use an If Then Statement to make sure you are not on current before you .Edit.

    Then to edit the current record just use the form and no DAO. Seems like a lot of work and a serious workaround but....

  9. #9
    jerem is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    88
    Alright. Well, thanks for your help. I will keep on searching. I just can't believe that a set of records could not be updated by an update query...

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    ItsMe has a point.

    Setting value of current record: Me!UnitCost = 1

    Then run UPDATE:

    CurrentDb.Execute "UPDATE tablename SET UnitCost=1 WHERE ID <> " & Me.ID

    Or in the loop using RecordsetClone:

    If .ID <> Me.tbxID Then
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    jerem is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    88
    Yes true. I had thought of somehow updating the current record separately but I wanted to explore this as a last resort solution. I always prefer getting things done clean and explore all the possibilities before going dirty ;-)

    Seems that we have reached that point so I'll give it a try. Thanks ItsMe!

  12. #12
    jerem is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    88
    The result looks good. the only issue now is that it adds an empty record to my continuous form. Any idea why it would do that?
    Here is the code.
    Code:
    Private Sub cboPoCurrency_AfterUpdate()
    On Error GoTo ErrHandler
        Dim db As Database
        Dim strSql As String
        Dim dblRate As Double
        Set db = CurrentDb
        dblNCostR = DLookup("ExRate", "Currency", "ID = " & [cboCurrency])
        dblRate = dblNCostR / dblOCostR
        With Me.sbfProductDetails.Form
            .txtUnitCost = .txtUnitCost * dblRate
        End With
        DoCmd.SetWarnings False
            strSql = "UPDATE QuoteLineItems SET QuoteLineItems.UnitCost = [UnitCost] * " & dblRate & _
                    " WHERE QuoteLineItems.QuoteID = " & Me.txtID & ";"
        DoCmd.RunSQL strSql
        Me.txtExRate.Value = dblNCostR
        Set db = Nothing
    ExitSub:
        Exit Sub
    ErrHandler:
        Call ErrorAlert
        Resume ExitSub
    End Sub

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    By empty record you mean only txtUnitCost has a value? That makes me think focus is on New Record row when the textbox value is set. Could be that with the AfterUpdate event, focus has moved to the next record and if you were on the last record then the focus would now be New Record.

    If you are going to use SetWarnings then should reset back to True at end of procedure. Use CurrentDb.Execute and can eliminate SetWarnings.

    Value is default property of data controls. Do not have to type it but certainly doesn't hurt if you do.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    jerem is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    88
    Yes you are right. This only happens if the cursor is in a new record. I made the other changes as suggested...
    Code:
    Private Sub cboPoCurrency_AfterUpdate()
    On Error GoTo ErrHandler
        Dim db As Database
        Dim strSql As String
        Dim dblRate As Double
        Set db = CurrentDb
        dblNCostR = DLookup("ExRate", "Currency", "ID = " & [cboPoCurrency])
        dblRate = dblNCostR / dblOCostR
        With Me.sbfProductDetails.Form
            .txtUnitCost.Value = .txtUnitCost.Value * dblRate
        End With
            strSql = "UPDATE QuoteLineItems SET QuoteLineItems.UnitCost = [UnitCost] * " & dblRate & _
                    " WHERE QuoteLineItems.QuoteID = " & Me.txtID & ";"
        db.Execute strSql
        Me.txtPOExchRate.Value = dblNCostR
        Set db = Nothing
    ExitSub:
        Exit Sub
    ErrHandler:
        Call ErrorAlert
        Resume ExitSub
    End Sub

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Might try BeforeUpdate event.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Recordset loop not updating and breaks
    By Ruegen in forum Programming
    Replies: 1
    Last Post: 02-24-2014, 05:33 PM
  2. Replies: 7
    Last Post: 08-01-2013, 11:52 AM
  3. Loop Not Progressing Through Recordset
    By nmlinac in forum Programming
    Replies: 1
    Last Post: 02-15-2013, 10:54 AM
  4. Double loop recordset
    By silverspr in forum Programming
    Replies: 7
    Last Post: 03-07-2012, 01:43 PM
  5. Loop through recordset
    By eliedebs in forum Programming
    Replies: 1
    Last Post: 01-11-2012, 12:26 AM

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