Results 1 to 6 of 6
  1. #1
    Join Date
    May 2007
    Posts
    74

    Unanswered: Getting 'Error 3072' when editing a recordset

    I'm seeing the following error when editing a recordset:

    Run-time error '3072':

    Cannot update. Database or object is read-only.


    I am trying to update a field in a table based upon selections made in a listbox. The RecordSource for the listbox is a dynaset query based on the table that I want to modify.

    Here's my code:

    Code:
        If Not IsNull(Me!cbxGrouping) Then
        
            Set db = CurrentDb
            Set rst = db.OpenRecordset(Me.lstValues.RowSource, dbOpenDynaset)
            rst.MoveFirst
            
            For idx = 0 To Me.lstValues.ListCount - 1
                If Me.lstValues.Selected(idx) Then 
                    With rst
                        .Edit   <== Crashes here
                        !Grouping = Me!cbxGrouping
                        .update
                    End With
                Else
                    ....
                End If
                rst.MoveNext
            Next
        Else
            MsgBox ("A Grouping must be selected before making associations")
        End If
        
        rst.Close
    I'm sure that I'm missing something that is basic. My understanding of a dynaset recordset is that if I modify (and update) it, then the underlying records in the table that feeds the recordset will get modified. Is this not correct?

    Thanks ...

    azjazz
    Last edited by azjazz; 06-01-07 at 18:38.

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    I'm not sure (since I mostly write in ADO) but is the .Edit necessary in DAO?
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    the .Edit is required in DAO (if you intend to edit).

    the problem is un-diagnosable without the .rowsource SQL, but odds-on you have some sort of join in the .rowsource that wont let you update.

    add a breakpoint on the line
    rst.MoveFirst
    and when it stops, Ctrl-G (open the immediate window) and type
    ? Me.lstValues.RowSource
    hit return and post the result.

    you can also check it out yourself - new query, SQL view, paste in the SQL you just dumped to the immediate window, run the query and see if you can update.

    izy
    currently using SS 2008R2

  4. #4
    Join Date
    May 2007
    Posts
    74
    Hi, guys -

    My RowSource query is "joinless", based upon a single table. Here it is:

    SELECT DISTINCT D.id, D.Name, D.TagSet FROM Document AS D ORDER BY D.Name

    I just realized something ... could the query/tables be uneditable because I am using the AS clause?

    Edit: (OK, I just checked by removing the "AS" clause, and that wasn't it.)

    azjazz
    Last edited by azjazz; 06-04-07 at 15:22.

  5. #5
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    If it's DISTINCT, I don't believe you can use the .Edit (even in DAO). Try making it into an actual query and you probably won't be able to edit the data, remove the DISTINCT and you will be able to edit the data.
    Last edited by pkstormy; 06-04-07 at 15:23.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  6. #6
    Join Date
    May 2007
    Posts
    74
    Quote Originally Posted by pkstormy
    If it's DISTINCT, I don't believe you can use the .Edit (even in DAO). Try making it into an actual query and you probably won't be able to edit the data, remove the DISTINCT and you will be able to edit the data.
    Thanks, pkstormy - That was it!

    This forum is AWESOME!

    azjazz

Posting Permissions

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