Results 1 to 7 of 7
  1. #1
    markcrobinson is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    New Hampshire, US
    Posts
    31

    Append query sort problem, but only when called from a within a module

    Scratching my head.



    I have an append query with a multi-level sort on two fields that works fine when I run the query normally.
    When I run the query in a vb program with the docmd.openquery ("Queryname") the sort doesn't work - table isn't in the correct order.
    When I run the Query in the Immediate window, it works fine.

    My DoCmd.Openquery command follows a docmd.runsql "UPDATE" command on the same table.
    Thinking that maybe it was a timing issue, I stuck a MsgBox between the docmd.runsql and the docmd.runquery and all works find.

    Best guess is the docmd.openquery is running before the docmd.runsql completes.
    Is this possible?
    If so, Is there a better way to insert a delay than put up a msgbox?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    You use RunSQL to execute an UPDATE, why not RunSQL for INSERT?

    Why should sort order of INSERT even be an issue? Sort in SELECT queries.
    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.

  3. #3
    markcrobinson is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    New Hampshire, US
    Posts
    31
    There is a meaning behind my madness. I like the RunSQL format, and usually use it but this last Append query is a complex one that will change frequently. The Query GUI is an asset here.
    I'm preparing a file for export; taking the import, massaging it, then sending it with the Append query, in the proper order, to the Output table.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Change in what way? How does a saved query object provide flexibility? I don't programmatically run action query objects, I use CurrentDb.Execute on an SQL string I build in code.
    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.

  5. #5
    markcrobinson is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    New Hampshire, US
    Posts
    31
    I really appreciate your feedback and will consider your suggestions. It sounds like you are well above my pay grade. I do frequently run action query objects programatically but don't understand why this one isn't working without the delay.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Neither do I and would have to do some testing.

    If you want to provide db, follow instructions at bottom of my post.
    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
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800

    Post

    table isn't in the correct order.
    Not trying to be snippy here, but who cares? You rarely ever have to worry about how a table sorts its records - nor should you. A table has oft been compared to a bucket of marbles, i.e there is no sort or guarantee of a sort. Not even when it uses autonumbers. Sorting is what queries do, and forms based on them will abide by the sort.

    Only once or twice in 20 years did I ever have to worry about a sort in a table but I can't recall why. That was controlled via a number field that the table was sorted on, but those were program support tables, not regular record keeping tables. Maybe you have a valid case as to why the records must be entered in a particular order. If so, I'd be interested to know what that is. I'll speculate here that the designers of Access considered the analogy I gave when they decided not to control the order of an append query - assuming that the behaviour is normal and I'm not off my rocker.

    EDIT:
    Best guess is the docmd.openquery is running before the docmd.runsql completes. Is this possible?
    MY money is on No, not possible.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Append query, problem with key violation
    By FoolzRailer in forum Queries
    Replies: 2
    Last Post: 08-09-2016, 11:12 AM
  2. Append Query problem
    By BobW2961 in forum Access
    Replies: 6
    Last Post: 05-18-2016, 08:20 AM
  3. Is Form name available in called module?
    By Rich Fulton in forum Access
    Replies: 7
    Last Post: 08-29-2015, 06:47 AM
  4. Access/Append Query/Problem
    By Reety in forum Access
    Replies: 5
    Last Post: 03-11-2014, 12:05 PM
  5. append query: dlookup or dmax problem
    By jeffr27 in forum Queries
    Replies: 1
    Last Post: 05-10-2011, 09:25 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