Results 1 to 5 of 5
  1. #1
    Susy is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2014
    Posts
    134

    vba - If Event is True then Outlook message.


    Hi everyone,

    I am trying to "silently" send an email if for instance an event is trigger. In this case, if the amount of X is less to the amount of Y then send an email to remind me to buy more from product X.

    I will be using Outlook for this matter.

    The .Body should read something like "Your reserves from "Product X" are reaching its minimum. Please buy more of it"

    I hope anyone can help me with this.

  2. #2
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi susy

    this is the code I use to create an e-mail if a ticket is set to closed.

    you could change the code to something like this below, it checks if an e-mail address is present in a form, if not no e-mail is sent if one exists an e-mail is automatically sent and a message box pops up informing you, these can be removed by commenting it if required

    If IsNull(Me.UsersEMailAddress) Then
    MsgBox "This Ticket Has Been Closed. No E-Mail Has Been Set ", vbOKOnly, "Ticket Sent"
    Forms!OpenAssetNotes.Requery
    Else'this requires a refrence to outlook object libary
    Dim bStarted As Boolean
    Dim oOutlookApp As Outlook.Application
    Dim oItem As Outlook.MailItem

    On Error Resume Next

    'Get Outlook if it's running
    Set oOutlookApp = GetObject(, "Outlook.Application")
    If Err <> 0 Then
    'Outlook wasn't running, start it from code
    Set oOutlookApp = CreateObject("Outlook.Application")
    bStarted = True
    End If

    'Create a new mailitem
    Set oItem = oOutlookApp.CreateItem(olMailItem)

    With oItem
    'Set the recipient for the new email
    .BodyFormat = olFormatHTML
    .To = Me.UsersEMailAddress
    '.CC = DLookup("SupportEmail2", "Settings", "ID = 1")
    .Subject = Me.NoteType
    .HTMLBody = Me.Notes & "This Ticket Has Been Closed By " & Me.ClosedBy
    '.Display
    .Send
    End With

    If bStarted Then
    'If we started Outlook from code, then close it
    oOutlookApp.Quit
    End If
    Set oOutlookApp = Nothing
    Set oItem = Nothing
    MsgBox "This Ticket Has Been Closed. An E-Mail Has Been Sent To " & Me.OpenedBY, vbOKOnly, "Ticket Sent"
    'DoCmd.Close
    Forms!OpenAssetNotes.Requery

    End If

    End Sub

    hope this helps
    steve

  3. #3
    Susy is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2014
    Posts
    134
    Thanks Steve, let me see if I can figure out how to adapt it. I will let you know. :-)

  4. #4
    Susy is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2014
    Posts
    134
    Steve, a similar code should be inserted in the AfterUpdate event from the field I want to "test, right?

  5. #5
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi Susy

    sorry for the late reply

    yes, that's correct

    Steve

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

Similar Threads

  1. Message Box on Event
    By Benjiro in forum Modules
    Replies: 12
    Last Post: 03-02-2014, 04:26 AM
  2. Replies: 0
    Last Post: 03-11-2012, 09:19 AM
  3. bypass the Outlook security message
    By ybg1 in forum Programming
    Replies: 7
    Last Post: 12-21-2011, 10:28 AM
  4. Import Outlook email message
    By crowegreg in forum Import/Export Data
    Replies: 5
    Last Post: 09-27-2011, 11:10 PM
  5. Replies: 1
    Last Post: 03-09-2006, 01: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