Data Macros in Microsoft Access

Поделиться
HTML-код
  • Опубликовано: 19 сен 2022
  • In this episode, we're going to take an introductory look at Data Macros in our MS Access database. Data macros perform a similar function to "Triggers" in other database management systems, and they do that by allowing users to execute updates when a record is inserted, or when a record is updated, or other events. For example, when a price is updated in one table, that price update can be logged in another table for a price history. In today's example, we'll log an event record each time a new case management record is added to a database, putting the current user's name on the record in the process.
    Related Videos:
    How to Use Data Macros to Track Changes to Field Entries in MS Access
    • How to Use Data Macros...
    Data Macros in Microsoft Access
    You are watching this video now!
    How to Use Macros in MS Access
    • How to Use Macros in M...
    Join me on Patreon!
    / mackenziedataengineering
    Demo of my BZ RDP Cloaker:
    www.patreon.com/posts/how-to-...
    Want the code from this video?
    mackenziemackenzie.com/downloads
    For developers looking for a new role, check out and sign up:
    www.toptal.com/qKaO2b/worlds-...
    Needing to hire technical resources for your project? Get the best:
    www.toptal.com/qKaO2b/worlds-...
    Contact form you can find at www.mackenziemackenzie.com/
    Follow me on social media:
    / mackenziedataanalytics
    / seamacke
    / seamacke
    / seamacke
    / psmackenzie
    Get Microsoft Office including Access:
    click.linksynergy.com/fs-bin/...
    Got a RUclips Channel? I use TubeBuddy, it is awesome. Give it a try:
    www.tubebuddy.com/seanmackenz...
    #msaccess

Комментарии • 40

  • @siclucealucks
    @siclucealucks Год назад +1

    You are the only channel in my list where I have hit the bell icon :) Great Content

  • @imstevemcqueen
    @imstevemcqueen Год назад +1

    Excellent as usual

  • @handsome4819
    @handsome4819 Год назад +1

    That's really good. Thanks 👍

  • @garythedo
    @garythedo Год назад +1

    Thanks for these great videos! Hope that sometime you can do a video on migrating tables/backend to SharePoint. Thanks again!

  • @lorenzogaruglieri7046
    @lorenzogaruglieri7046 Год назад +1

    hi Sean. Congratulations on your videos. Question: is it possible through DataMacros to perform a personal function contained for example in a standard module?
    Thank you
    Lorenzo

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  Год назад +1

      Yes, you can do it. One way is to use SetLocalVar and setting the value to your VBA function. However, this crosses the line between the top and bottom layers of the application as I described in the beginning of the video. If you do it, it may sometimes break. Data Macros will trigger anytime data is updated, because they are tied to the ACE engine. If another program or script updates data, Data Macros will still trigger, but if you put a VBA function in there that process may have an error because your app is not running at the time data is updated. There can also be issues as to where your VBA resides, if the database is split, etc.

  • @SHCSBaker
    @SHCSBaker Год назад +1

    Great video! I'm thinking about changing my existing Audit Log to use this method. However I don't want the data macro to fire for every change, I think this could be addressed using a If Updated("myField") then RunDataMacro. I can't find many examples of how to use RunDataMacro, could you explain how this method works?

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  Год назад +1

      Good idea - you can use If Updated for this purpose. I’ll cover more like this in upcoming videos! Including RunDataMacro

  • @tonykutch4877
    @tonykutch4877 Год назад +1

    Great video! I'm a database guy from long ways back (try DBASE II on a Radio Shack TRS-80) and finally getting back into Access. Do most of my work directly on the back end, so I'm thinking data macros may provide a solution for my current project, though I'm not sure how complex the final solution will be. I've got an inventory of components, purchased from multiple vendors on multiple invoices. I already have a query set up to list individual component costs and quantities per invoice. My goal is to accumulate the total costs of the components used in an end item (always the same list of components) and update the component inventory as each end item is completed. Essentially looking to manage inventory use on a FIFO basis. Any suggestions you might have would be greatly appreciated. Thanks, again, for the great videos.

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  Год назад

      Oh man, TRS-80! That was my computer when I was a kid. Dungeons of Daggorath in black and white 3D wireframes.. good times. On your project, you could definitely use a status change trigger. If the order changes status to complete, execute your query with all the build component counts to reduce inventory by those counts for each component. On the event/trigger you can capture the order or assembly ID then use that ID as a parameter in your update query, updating all of them in one shot. Interesting project!

  • @fernandolucas2435
    @fernandolucas2435 Год назад +1

    Excellent!! How can I know the current user login in the FE?

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  Год назад +2

      In this example, we pretend that we created our own login system that stored the current user in tblCurrent. I will make a video on how to get the Windows login too, as this has been asked several times recently! cheers!

  • @999juanrivera1
    @999juanrivera1 Год назад +1

    In your video Sam did the update but in the log John was entered. ho can this be corrected to get the correct user name?

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  Год назад +1

      In our example, we pretend that we made John Doe log in to our app, and then we stored his name in tblCurrent while he uses the app. He is entering new cases for the other Case Workers, like a secretary.

    • @999juanrivera1
      @999juanrivera1 Год назад

      @@seanmackenziedataengineering OK got it. Thanks

  • @jot2243
    @jot2243 Год назад +1

    Hi Sean. I was trying to change the form to launch my MS-Access to a particular form (In the Access option, Current Database Tab) but each time and I did that, I got this warning message "The value of a Display Form property was invalid and was not saved" and it returns the value to none even though I have done it countless times before now. It won't change even if I open it again and change it to the form I want.
    I need your help to resolve this issue as I am stuck.

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  Год назад

      You probably need to open your database in exclusive mode. Someone (even you perhaps) may have another database lock open on the file.
      Open Access > Open > Browse > in the dropdown next to Open, choose Open Exclusive
      If you can't, you may need to ask others to close the file or restart your machine to remove the lock. Great question!

  • @siclucealucks
    @siclucealucks Год назад +1

    I have tried to use Environ("UserName") Instead of CurrentUser but unfortunately it seems that Environ functionset is not available for macros.

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  Год назад +2

      Great question. I will do another video to show how to get the *Windows* username. In this example, we pretend that we are building an app. We made John Doe log in, using our own login form, and he is making appointments for the other Case Workers. When he logged in, we stored his name in tblCurrent.

    • @siclucealucks
      @siclucealucks Год назад

      @@seanmackenziedataengineering Thats a great video Idea

  • @gerfer6261
    @gerfer6261 Год назад +1

    🎉🎉🎉

  • @golfmbavu4285
    @golfmbavu4285 Год назад +2

    Bonjour, je suivis votre tutoriel avec intérêt mais comment apprendre beaucoup plus en français

  • @vholas
    @vholas Месяц назад

    Very useful! After Update and After Insert events work for me, but if I use After Delete nothing happens. What am I doing wrong? Thanks

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  Месяц назад

      It is possible that what you try to do after the delete gets an error. Perhaps you refer to the deleted record or something like that. What does your After Delete macro do?

    • @vholas
      @vholas Месяц назад

      @@seanmackenziedataengineering I want to store in the LOG table information about inserted/changed/deleted records from the DATA table.
      If I use the code Value = [DATA].[ID] in the After Insert or After Update event, it works, but if I use it in the After Delete event, then a new record is not created in the LOG table. No error will appear...

    • @vholas
      @vholas Месяц назад

      I want to write to the LOG table the insertion/change/deletion of a record from the DATA table. I use the expression Value = [DATA].[ID]. It works for both After Insert and After Update events, but not for After Delete. No record will be created, no error will appear...

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  Месяц назад

      @@vholas it is likely because you refer to a value that is already deleted when the macro runs. You might try Before Delete instead so you can use the value before it is deleted. Let’s see how it goes 🛠️

    • @vholas
      @vholas Месяц назад

      There is no CreateRecord action available for the Before Delete event. I also tried accessing the previous value in a field by using syntax [Old].[Field Name] , but this doesn't work either.

  • @interestingamerican3100
    @interestingamerican3100 Год назад +1

    Holly &^$*%&! You can do that in Access?!?!