Results 1 to 5 of 5

Runtime Error '3027': Database or object is read only

  1. #1
    4x4Masters is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    3

    Runtime Error '3027': Database or object is read only

    I have the following code in a database but get an 3027 error when I run it.
    Everything else works except the bit I underlined
    I am trying to write strPreviousScore to the Score field for the current recordset
    Being a novice I am stuck on this problem and any help will be appreciated and restore my sanity

    EDIT: I changed the code to Set rst = dbs.OpenRecordset(strSQL) and now get a 3020 Error
    Now I am more confused, I figured that the 'type' setting was wrong but do not know which option to choose and rst!Score= strPreviousScore bit still does not work

    cheers
    Wayne


    CODE:

    Sub subInsertScores(strSQL As String, strMaxScore As String)
    Dim dbs As Database
    Dim rst As Recordset

    Set dbs = CurrentDb()
    Set rst = dbs.OpenRecordset(strSQL, dbOpenSnapshot, dbSeeChanges)

    '**Find the number of records.


    rst.MoveLast ' End of the recordset
    strRecordCount = rst.RecordCount ' Number of records

    strPreviousScore = 0
    strPreviousTime = 0

    'loop through each record and add score
    rst.MoveFirst
    For A = 0 To (strRecordCount - 1)
    strCurrentPoints = rst![Total Points]
    strCurrentTime = rst![TotalTime]
    strCurrentScore = rst![Score]


    If strCurrentPoints = strPreviousPoints Then rst![Score] = strPreviousScore

    '**set currents to previous here before moving to next record
    strPreviousPoints = rst![Total Points]
    strPreviousScore = rst![Score]
    strPreviousTime = rst![TotalTime]
    rst.MoveNext
    Next

    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    20,616
    Try dbOpenDynaset instead of dbOpenSnapshot. You should find full descriptions in VBA help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    4x4Masters is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    3
    I changed the code to Set rst = dbs.OpenRecordset(strSQL,dbOpenDynaset) and now get a 3020 Error (Update or CancelUpdate without Addnew or Edit) @ rst!Score= strPreviousScore

    I figure I need to tell it I want to edit rst![Score] now or the = needs to be an add or edit command

    Should add that this is the first time I have dealt with recordsets and am on a sleep learning curve

  4. #4
    4x4Masters is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    3
    pbaldy - Thanks for steering me in the right direction

    SOLVED: (changed code in bold)

    Sub subInsertScores(strSQL As String, strMaxScore As String)
    Dim dbs As Database
    Dim rst As Recordset

    Set dbs = CurrentDb()
    Set rst = dbs.OpenRecordset(strSQL, dbDynaset)

    '**Find the number of records.
    rst.MoveLast ' End of the recordset
    strRecordCount = rst.RecordCount ' Number of records

    strPreviousScore = 0
    strPreviousTime = 0

    'loop through each record and add score
    rst.MoveFirst
    For A = 0 To (strRecordCount - 1)
    strCurrentPoints = rst![Total Points]
    strCurrentTime = rst![TotalTime]
    strCurrentScore = rst![Score]

    rst.edit
    If strCurrentPoints = strPreviousPoints Then rst![Score] = strPreviousScore
    rst.update

    '**set currents to previous here before moving to next record
    strPreviousPoints = rst![Total Points]
    strPreviousScore = rst![Score]
    strPreviousTime = rst![TotalTime]
    rst.MoveNext
    Next

  5. #5
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    20,616
    Happy to help, and welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 04-15-2010, 09:43 AM
  2. Help With Runtime Error 4248
    By KLahvic in forum Programming
    Replies: 1
    Last Post: 04-09-2010, 07:47 AM
  3. Runtime 3075 error
    By whm1 in forum Programming
    Replies: 4
    Last Post: 03-24-2010, 02:50 PM
  4. Replies: 5
    Last Post: 08-05-2009, 04:07 PM
  5. Read only Access Database
    By Rameez in forum Access
    Replies: 7
    Last Post: 06-23-2009, 12:30 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
  •  
Tech Forums: Microsoft Office Forums