DAO Recordsets

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sc5502
    New Member
    • Jun 2014
    • 102

    #1

    DAO Recordsets

    Background:
    Front end: MS Access 2013
    Back end: SQL Server 2008

    I have a program that does the following:
    Code:
     ' open Work_Downtime query
         Dim rsQ As DAO.Recordset
         Dim dbQ As Database
         Set dbQ = CurrentDb
         Set rsQ = dbQ.OpenRecordset("Q_dbo_tblDowntime", dbOpenDynaset, dbSeeChanges)
    
         ' are their records to delete?
         If rsQ.RecordCount = 0 Then GoTo noQRecords
              
         Dim downtime As Integer
          
         ' position to read
         rsQ.MoveFirst
    
         While Not rsQ.EOF
         
               If rsQ.Fields("FixReject") = "0" Then
                  downtime = DateDiff("n", rsQ.Fields("Start_Datetime"), rsQ.Fields("End_DateTime"))
               End If
                 
                            
               rsQ.Edit
                 rsQ.Fields("DT") = downtime
               rsQ.Update
               
               rsQ.MoveNext
         Wend
    I get the following error when I run the program. What is wrong?

    Error#: 3164 Field cannot be updated
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    Is Q_dbo_tblDownti me linked to a table or view in SQL Server? Do you have Write permissions to it?

    Comment

    • sc5502
      New Member
      • Jun 2014
      • 102

      #3
      it is a query linked to a table on SQL Server

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Your query is probably written in a way where it's not editable.

        Comment

        • Seth Schrock
          Recognized Expert Specialist
          • Dec 2010
          • 2965

          #5
          Good point Rabbit.

          @sc5502 Please post your query SQL (using code tags). Also, is the query in Access or on the SQL Server?

          Comment

          • jforbes
            Recognized Expert Top Contributor
            • Aug 2014
            • 1107

            #6
            You might be able to simplify this considerably if you were to write/create an Update Query against the Base Table.

            Comment

            Working...