Results 1 to 4 of 4
  1. #1
    Robeen is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596

    Test for success of "DoCmd.RunSQL strSQL" Insert Statement.

    How can I Test for success of "DoCmd.RunSQL strSQL" Insert Statement.
    I am archiving records to an external Access DB - and it is working.
    Is there a 'Best Practice' for verifying that the Insert to the external DB was successful before I Delete the Archived row[s] from the Production DB?

    I'd appreciate if you could point me in the right direction. I have not been able to find the answer on GoogleIsMyFriend yet!!
    Currently, I am turning the SetWarnings Off before the Insert and On after.



    Thanks in advance.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Use Execute:

    Code:
      Dim db                      As DAO.database
      Dim intAppendCount          As Integer  
    
      Set db = CurrentDb
    
      db.Execute "qryAppendAutoGas"
      intAppendCount = db.RecordsAffected
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Just to add to pbaldy's note -

    You should use

    db.Execute "qryAppendAutoGas", dbFailonerror

    This will cause a runtime error to be generated if the db.Execute command causes an error.

    John

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sorry, I should have added that. It's optional, and in the app I cut that from I didn't want errors to be raised (automated import routine). Most of the time you would.
    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: 1
    Last Post: 11-13-2014, 02:54 PM
  2. Replies: 2
    Last Post: 07-15-2014, 07:22 PM
  3. Replies: 6
    Last Post: 02-24-2014, 09:26 AM
  4. Replies: 6
    Last Post: 01-29-2014, 08:03 AM
  5. problem with my DoCmd.RunSQL statement
    By cgclower in forum Access
    Replies: 1
    Last Post: 07-24-2011, 06:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums