Results 1 to 7 of 7
  1. #1
    john134 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2014
    Posts
    42

    Post Update query. Executing in vba

    I have an Update action query that works manually. I can view it
    correctly and then click on Run (!) and it works. However, when I
    try to run it in vba with the DoCmd.OpenQuery "queryname", it does
    not work.

    Any suggestions appreciated.

    john134

  2. #2
    john134 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2014
    Posts
    42
    I should have mentioned that this is in Acess 2007.

    john134

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by john134 View Post
    However, when I try to run it in vba with the DoCmd.OpenQuery "queryname", it does not work.
    What does "it does not work" mean? Errors?? Messages??? How do you know "it doesn't work"?

    That is like saying "My car does not work. What is wrong with it?" More details please.......

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    And what code, exactly, are you using?

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    This is not my area of expertise, but the OpenDataMode argument accepts no 'Update' parameter when using DoCmd.OpenQuery...in fact I'm pretty sure you can do no Action Query from Access, in this manner. I'm pretty sure you need to use something along the lines of

    DoCmd.RunSQL "UPDATE..."

    or, preferably,

    CurrentDb.Execute " UPDATE...", dbFailOnError

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    I don't 'run' query objects, I use VBA as shown by Linq.

    However, just did a test. OpenQuery does run the saved query object and records are updated.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    john134 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2014
    Posts
    42
    I am updating a record from Table B to Table A. After I run the query manually
    I look in Table A and find that the update occurred. When I ran it with vba code the
    record in Table A was not updated.

    But, the problem has been solved.

    The record in Table B was located in a subform. I had intitated the event on a control in
    that subform and it didn't work. However, when I initiated the query event on the subform's
    On Exit, the update query worked.

    john134

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

Similar Threads

  1. Replies: 8
    Last Post: 01-09-2016, 04:51 PM
  2. executing update query
    By deepucec9 in forum Queries
    Replies: 2
    Last Post: 10-27-2015, 10:02 AM
  3. Need Help executing an update in form
    By ismith in forum Forms
    Replies: 17
    Last Post: 01-20-2012, 08:42 AM
  4. Executing Query to Excel?
    By objNoob in forum Programming
    Replies: 1
    Last Post: 03-17-2010, 04:59 PM
  5. Replies: 0
    Last Post: 04-21-2006, 06:55 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
  •  
Other Forums: Microsoft Office Forums