Results 1 to 10 of 10
  1. #1
    rafpac is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2022
    Posts
    8

    Unexplainable problem where an Update query unintentionally triggers before update table macro

    Hi All,



    Hope the year has been good to you. I have an interesting situation and not sure why this is happening.

    I have a table with 2 columns impacted by a macro. The first column is a status column and the second column is a date column.

    The before update macro is setup that when the status field (which is a data validation drop down, either "open" or "closed") is set to closed, then the date column will equal Now(), else Null.

    Then I created an update query on access, which takes 2 columns called "Major" and "Minor" from another table and updates the "Major" and "Minor" columns in the first table when run.

    So the macro is dealing with the "Status" and "Date" columns while the Query impacts the "Major" and "Minor" columns.

    Now what's intriguing is that when the update query is run, for some reason the macro seems to be triggered as well, then takes all the records with the Status as "Closed" and changes their date columns value to Now() when the update query is run?

    This is strange as the update query should not be impacting the before update macro.

    Does anyone know why this maybe and how I can resolve this problem? Thanks.

    Kind Regards,

    Raf

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Are you talking about Data Macro? I don't see a Before Update data macro. Do you mean Before Change?

    I just did a test and this is apparently normal behavior. UPDATE query is editing record and that triggers Before Change macro.

    I never use macros but I would expect same issue with form's VBA Before Update event.
    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
    rafpac is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2022
    Posts
    8
    Quote Originally Posted by June7 View Post
    Are you talking about Data Macro? I don't see a Before Update data macro. Do you mean Before Change?

    I just did a test and this is apparently normal behavior. UPDATE query is editing record and that triggers Before Change macro.

    I never use macros but I would expect same issue with form's VBA Before Update event.

    Thanks for looking into this. Apologies I indeed meant Before Change Macro. So if this is normal behavior that all update queries will automatically trigger before change macros, any alternatives to macros for me to auto populate the date field when the status field is changed to Closed?

  4. #4
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    The Data macro operates for all data changes - it pays no attention to any form related events, it's completely independent.
    That's the point of them, to capture changes to data made anywhere, by anything.

    You have to decide to either only use the form events for this or rely on the Data Macro to do the job, not both, as inevitably there will be a conflict.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Use a form for user interaction. Use Status combobox AfterUpdate event (macro or vba) to modify other field data.

    Users should not interact directly with tables and 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.

  6. #6
    rafpac is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2022
    Posts
    8
    Quote Originally Posted by June7 View Post
    Use a form for user interaction. Use Status combobox AfterUpdate event (macro or vba) to modify other field data.

    Users should not interact directly with tables and queries.
    Hi June7,

    Thanks again. So to clarify the users are indeed using a form. The issue I am having has nothing to do with user interactions. The problem here is I am indeed currently running a change macro that populates a field with a date when the status of another field is changed to closed. But I also have an update query which is used to bulk import relevant data into the same table from another table monthly. But as you have pointed out that the update query will also trigger the macro.

    So I have to either scrap the update query or scrap the macro. So I am asking if there is another way outside of Macros to populate date when the status is changed? If not then is there a way to bulk update 2 fields in this table using data from another without an update query?

    Let me know if you have any solutions for this. Thanks.

    Kind Regards,

    Raf

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I already suggested using control AfterUpdate event instead of data macro.

    Already established that it doesn't matter how field data is changed, will trigger table BeforeChange event.
    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.

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Raf,
    Can you post a copy of your database or some mockup that highlights the issue?
    Or tables and relationships?
    Perhaps a sample showing the tables and what causes the status to change and result.
    I need more context.

  9. #9
    rafpac is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2022
    Posts
    8
    Ah I see what you mean. AfterUpdate event instead of a BeforeChange event. But anyways your advice did help me out immensely. Because I deleted the Before Change Macro from the table and implemented a VBA script on the form end to enter Now() into the date field when the user presses a button to close the record. And voila...I can use the Update query on the table end without triggering anything on the form end. Thanks so much!

  10. #10
    rafpac is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2022
    Posts
    8
    Hi Orange,

    The status changes to close by clicking a button on the front end form by the user. Then a VBA script on the form side changes the table data to Closed. So to solve my problem I just added another line on the form side to enter the Now function into the table date field. Now the update query on the table side doesn't trigger anything.

    Anyways shout out to all you guys for helping!

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

Similar Threads

  1. Replies: 10
    Last Post: 07-14-2021, 02:08 PM
  2. Update Query with Criteria in update to table
    By tanner.morgan in forum Queries
    Replies: 3
    Last Post: 08-28-2018, 07:56 AM
  3. Replies: 4
    Last Post: 04-27-2016, 04:36 PM
  4. Query table update problem
    By sroy in forum Forms
    Replies: 1
    Last Post: 06-17-2013, 02:41 AM
  5. Replies: 1
    Last Post: 02-08-2012, 04:50 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