Results 1 to 10 of 10
  1. #1
    Famfeld is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2021
    Posts
    9

    Email when a new record is created

    Hi,



    I know there are already a few posts with similar info, but specifically I would like to learn how to have access send emails to a few recipients when a new record is created.

    Perhaps someone can get me a link to a tutorial or another post?

    Thanks,

    Famfeld

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    set a variable when they begin a new record. then email when they save it.

    Code:
    public gbNewRecBegin as Boolean
    
    
    
    'here they start a new record
    Private Sub Form_BeforeInsert(Cancel As Integer)
    gbNewRecBegin = True
    End Sub
    
    
    
      'then when they save it.
    Private Sub Form_AfterUpdate()
    if gbNewRecBegin then
      DoCmd.SendObject acSendQuery, "qsNewRec", acFormatXLS, "name@aol.com", , , "Subject", "message"
      gbNewRecBegin =false
    endif
    End Sub

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,970
    Use form AfterUpdate event.

    SendObject is simplest method to send email.

    And now I see ranman already posted sample 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.

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,829
    As you say, tons of examples on how to send email using Access, so I suspect you're needing to know how to trigger it for your case. For that I'd say use form AfterInsert event.

    EDIT - AfterUpdate will fire when record is edited - not what is needed here, I think?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,970
    That is better. Don't have to test for new record and no unnecessary calls to procedure.
    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
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,451
    Another option is to use a data macro when a new record is created. The macro would need to call a vba function to send an email. Plenty of examples how to send an email

  7. #7
    Famfeld is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2021
    Posts
    9
    Thanks for helping.

    I get an error that qsNewRec doesn't exist as an object. I get the main idea of what is being done, but I also I don't understand where I am telling Access or VBA to communicate with an email host or server?

    Is there an example in a video or a tutorial that someone could point me to?

    Thanks again,

    Famfeld

  8. #8
    Famfeld is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2021
    Posts
    9
    Thanks for the help. Would it be good for me to attach my project to this thread?

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,024
    That should be the name of your query, that produces what you class as new records.?
    Perhaps at the end of the day, select all the records created today (for that you would need to store the date created) and email that query to your recipients.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,970
    Exactly what do you want to include in this email? Just a record ID or data from each field? Can either send an object (query, form, report) as a PDF attachment or don't send object and build an email body as a string that would be part of the Message argument.

    This is a common topic. Check out the "Similar Threads" found below this discussion. One of them is https://www.accessforums.net/showthread.php?t=49199
    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.

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

Similar Threads

  1. Replies: 5
    Last Post: 08-24-2017, 09:03 PM
  2. Replies: 3
    Last Post: 11-18-2015, 05:39 PM
  3. Replies: 1
    Last Post: 12-22-2014, 09:21 PM
  4. Action on record before PK is created (record saved)
    By chris.williams in forum Forms
    Replies: 4
    Last Post: 09-14-2012, 10:41 PM
  5. Email created from Access is in the wrong format
    By Stick in forum Programming
    Replies: 0
    Last Post: 09-25-2006, 12:48 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