Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2019
    Posts
    16

    How to have Update Query's run automatically


    I have created several update queries, but I have to run them manually, what do I need to do have them update the fields/tables as I go from record to record to update automatically?
    Attached Files Attached Files

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    You could have a small routine that -once you have reviewed the parameters for each update query, executes these queries one after the other. If there is some criteria that would prevent a query to run , you could trap and give a Message to the user.
    If all queries must complete successfully, or no updates should be applied, you will have to consider Transaction Logic.

    It isn't clear from your database, what should trigger the execution of any or all update queries.

    Here's a recent example from a database I have that runs several routines and a query in succession. The DoEvents line provides a slight interrupt for Access to let the processor do other things.

    This all gets started when I click on a label on a form
    Code:
    Private Sub Label0_Click()
    InternetAvailabilityFullProcess
    End Sub
    And this is the series of actions that gets executed.

    Code:
    Sub InternetAvailabilityFullProcess()
    10        On Error GoTo InternetAvailabilityFullProcess_Error
              ' make sure you have saved a copy of the Events (UniversalTelemetryClient)
              ' as a .txt file "C:\users\jack\documents\AllEventsRaw.txt"
              '
              'Run ImportEventsWithSpec to get txt data into  table ALLEventsRaw
              'Run the query to get event 55 data
              'Run the prepareInternetEventsJED to get proper Date and Time info
              'Run the ProcessInternetAvail to get a printout/txt file showing outages
              ' and durations --file is "c:\users\jack\documents\BellInternetDrops" & Format(Date, "MMMDD") & Format(Time, "_HHAM/PM") & ".txt"
              '
    20        Debug.Print "starting the import  at " & Now
    30        CurrentDb.Execute "Delete From AllEventsRaw", dbFailOnError
    40        DoEvents
    50        ImportEventsWithSpec
    60        Debug.Print "Import completed at " & Now
    70        DoEvents
    80        CurrentDb.Execute "Delete From InternetEventsJED", dbFailOnError
    90        Debug.Print "Running query to extract proper Date and time and only Event (55)"
    100       DoEvents
    110       DoCmd.OpenQuery "qInternetLog"
    120       Debug.Print "Query finished at " & Now
    130       Debug.Print "Preparing the InternetEventsJED table to remove duplicate/replicate records at " & Now
    140       prepareInternetEventsJED
    150       DoEvents
    160       Debug.Print "Finished preparations at " & Now
    170       ProcessInternetAvail
    180       Debug.Print " Finished processing outages and duration at " & Now
    190       Debug.Print " The file is available at " _
              & "c:\users\jack\documents\BellInternetDrops" & Format(Date, "MMMDD") & Format(Time, "_HHAM/PM") & ".txt"
              '
    200     MsgBox " The file is available at " _
              & "c:\users\jack\documents\BellInternetDrops" & Format(Date, "MMMDD") & Format(Time, "_HHAM/PM") & ".txt", vbOKOnly
              '
    210       On Error GoTo 0
    220       Exit Sub
    
    InternetAvailabilityFullProcess_Error:
    
    230       MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure InternetAvailabilityFullProcess, line " & Erl & "."
    
    End Sub


    Good luck.

  3. #3
    Join Date
    Jul 2019
    Posts
    16
    Currently in test mode, I enter in all the data in each of the forms and then I run the Queries in the order that they are in the list. The ideal would be that the query would run automatically after I select Save for each subform in the mainform.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    I think our posts overlapped. Review my post and see if that helps.

  5. #5
    Join Date
    Jul 2019
    Posts
    16
    So I would create a version of this as an Event Procedure, On Click of my Save Record (as an example)?

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Yes, that's where I'd start.
    I'd include some Debug.Print statements to help with any debugging and to give some constructive feedback to your efforts.
    You can remove the Debug stuff hen it's working as intended.

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

Similar Threads

  1. Replies: 1
    Last Post: 10-19-2018, 04:27 PM
  2. Update table from query automatically
    By charly.csh in forum Queries
    Replies: 12
    Last Post: 11-19-2014, 02:57 PM
  3. Query to automatically update report
    By kathi2005 in forum Access
    Replies: 13
    Last Post: 10-31-2011, 05:01 PM
  4. Automatically Update Query Parameter w/ Code
    By benthamq in forum Programming
    Replies: 2
    Last Post: 08-20-2011, 03:46 PM
  5. Help Automatically running and Update Query
    By JohnRandolphSTL in forum Queries
    Replies: 8
    Last Post: 04-13-2010, 02:08 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