Number of records changed by an action query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thefj
    New Member
    • Nov 2006
    • 2

    Number of records changed by an action query

    Hey all,

    As part of an access application, I am importing data from an XML file into a table, then using an update query to process the imported data into various other tables in the database where it belongs. I have the queries running fine, but I cannot for the life of me find out how to, from a VB code perspective, get the number of records that will be updated (or were updated) by a query.

    I'm trying to make something similar to the default Access warning message box that says "You are about to update XX record(s)", except a custom message that more closely reflects what the user is actually trying to do when the query is executed.

    The closest I've got it using an SQL Count() function in a SELECT query based on the update query I have just run, but it seems a bit of a long way of going about it.

    Any help appreciated.
  • pks00
    Recognized Expert Contributor
    • Oct 2006
    • 280

    #2
    Run an action query using currentdb.execu te then find out number of records modified

    eg

    Dim db As DAO.Database


    Set db = CurrentDb
    db.Execute "UPDATE mytable SET myfield=22"

    msgbox db.RecordsAffec ted


    If it complains about dao, u need to add it as a reference, in vba window go to tools/references then check microsoft dao 3.6 object library

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      I love learning new things on here.
      Thanks pks00 - this should prove uber-useful.

      Comment

      • PEB
        Recognized Expert Top Contributor
        • Aug 2006
        • 1418

        #4
        Yeah,

        You're a great girl pks00 :)

        Never used a staff like this one...

        msgbox db.RecordsAffec ted

        Is needed to use Begintrans and CommitTrans methods with this methode?

        My God you're pleinty with surprises..

        ;)


        Originally posted by pks00
        Run an action query using currentdb.execu te then find out number of records modified

        eg

        Dim db As DAO.Database


        Set db = CurrentDb
        db.Execute "UPDATE mytable SET myfield=22"

        msgbox db.RecordsAffec ted


        If it complains about dao, u need to add it as a reference, in vba window go to tools/references then check microsoft dao 3.6 object library

        Comment

        • thefj
          New Member
          • Nov 2006
          • 2

          #5
          You have no idea how much hair you have prevented me losing! I can't believe such a simple and useful reporting method is so difficult to find.

          Thanks :)

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #6
            I'm with you on that!

            Comment

            • pks00
              Recognized Expert Contributor
              • Oct 2006
              • 280

              #7
              Howdo, Peb

              and thanks all:)

              To tell you the truth, I have no idea whether it works with BeginTrans/CommitTrans. Ive never used these methods with DAO before#
              Sorry



              Originally posted by PEB
              Yeah,

              You're a great girl pks00 :)

              Never used a staff like this one...

              msgbox db.RecordsAffec ted

              Is needed to use Begintrans and CommitTrans methods with this methode?

              My God you're pleinty with surprises..

              ;)

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32633

                #8
                It is probably possible to use this with begin and end trans, but I'm fairly sure they're not required.

                Comment

                • PEB
                  Recognized Expert Top Contributor
                  • Aug 2006
                  • 1418

                  #9
                  For me it's curious where Access keeps the information for the affected records if this isn't in the buffer where it keeps info for the transactions...

                  It's thing that should be checked!

                  Comment

                  Working...