Results 1 to 14 of 14
  1. #1
    blue4512 is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    26

    Macro on New Record

    I would like to record the user's name that enters new records.



    To accomplish this I am thinking I need to run a macro that that updates the appropriate field but I am not sure of the best event to trigger the macro. Perhaps there is a better way.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    One of the insert events, probably the after insert event.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    blue4512 is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    26
    After Insert is a good option - thank you. Is there a way to only apply the action to the active record? Condition?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Typically you would have the macro set a field on the form to your value, which would only apply to the active record.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    blue4512 is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    26
    If I use the Form property event - after insert
    and run the macro it updates all records - I just want to update the current record

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    It would be helpful if you specified what actions the macro takes. It sounds like you're running an update query instead of setting a form control. If so, you probably need to add a criteria to the query.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    blue4512 is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    26
    the form enters new contacts
    the update query adds name/date/time
    I only want it to run on new/changed records
    thanks!

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Like I said, add a criteria to the query that refers to the record on the form.

    If you want it to run on changed records, you probably want the after update instead of after insert event.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    blue4512 is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    26
    Dumb question - How do i do that from the query when it is run form the a macro on the form?

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    In the Criteria row of the query design grid, under the appropriate field(s), add a reference to the appropriate form control(s). It will look like the above, or you can right-click and select Build.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    blue4512 is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    26
    After Insert is a good option - thank you. Is there a way to only apply the action to the active record? Condition?

    That's what I was thinking, do you know the criteria to use?

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    If you're using an update query, it needs to have a criteria. The macro condition won't have any effect on which records the update query updates. Only a criteria will.

    As I mentioned before, the more common approach (presuming the target fields are in the same table the form is bound to) is to simply have these fields on the form (can be hidden) and use SetValue in your macro to place your values. They will automatically save to the table for the correct record.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    blue4512 is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    26
    I have a unrelated signIn table and a customer table
    When a customer is added or changed I want to record the name of the person signed in.

    I am not familiar with SetValue in a macro, I did not find it as an action option - can you give me any other information on SetValue?

    I appreciate you help!

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    If you're not seeing it as an option, with the macro in design view click on "Show all Actions" on the ribbon. You should see it then. There should be info on it in help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 2
    Last Post: 06-06-2011, 04:18 PM
  2. Help With Macro's
    By GDubbs780 in forum Programming
    Replies: 1
    Last Post: 02-25-2011, 11:43 AM
  3. Replies: 0
    Last Post: 01-12-2011, 12:43 PM
  4. Help on macro to scroll one record back?
    By getholdofjoru in forum Forms
    Replies: 2
    Last Post: 06-19-2010, 03:01 PM
  5. MACRO help please
    By DianeG in forum Forms
    Replies: 2
    Last Post: 04-20-2010, 07:19 AM

Tags for this Thread

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