Records Affected

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lewe22
    New Member
    • Sep 2007
    • 94

    Records Affected

    I am performing a series of updates from a command button on an access form. I want to record the number of records affected for each update transaction.

    I have simplified some code..
    Private Sub cmdTest_Click()
    Dim db As Database
    Dim Test1, Count1 As String

    Set db = CurrentDb()
    Test1 = "UPDATE TestTable SET TestTable.TestF ield = '1'" & _
    "WHERE (((TestTable.Us er)='Alex Lewendon'));"

    db.Execute Test1
    'db.RecordsAffe cted = Count1

    MsgBox "Update Complete. " & CStr(db.Records Affected) & " records were updated successfully"

    End Sub

    As you can see i am able to show the number of affected records in a message box, but as soon as i set that value to equal a variable i receive the error message 'can't assign to read only property'.

    As my actual code is performing a number of updates i want to be able to store the number of affected records for each update. Those numbers will later be written to another table..

    Does anyone have any ideas??? I'm stuck.
  • hariharanmca
    Top Contributor
    • Dec 2006
    • 1977

    #2
    Yes that is an read only property, so you cannot asigen any value.

    Comment

    • Lewe22
      New Member
      • Sep 2007
      • 94

      #3
      Ok, but how can i store that value to use later??

      Comment

      • hariharanmca
        Top Contributor
        • Dec 2006
        • 1977

        #4
        I cannot get what you mean?

        Why you want to use it later. Do you mean overall updation in each record ?

        If yes then use another field to keep counting.

        Comment

        • jamesd0142
          Contributor
          • Sep 2007
          • 471

          #5
          from my experience in vb.net, i had to use the fill adapter, dataset etc... in order to record how many changes where made to the database.

          Comment

          • Lewe22
            New Member
            • Sep 2007
            • 94

            #6
            A record of each update performed is to be stored in a seperate 'update log' table.

            The update table has the following columns:

            User, Update Type, DateTime, NumberOfRecords Updated.


            Perhaps there is an easier way than using 'Records Affected'???

            Comment

            • QVeen72
              Recognized Expert Top Contributor
              • Oct 2006
              • 1445

              #7
              Hi,

              First declare Count1 as a Long variable and rec affected shud be on the right side:

              Count1 = db.RecordsAffec ted

              REgards
              Veena

              Comment

              • Lewe22
                New Member
                • Sep 2007
                • 94

                #8
                Thanks QVeen72. That worked perfectly!

                Comment

                Working...