Results 1 to 6 of 6
  1. #1
    Cran29 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2010
    Posts
    38

    Date event e-mail

    Would it be possible to automatically have access e-mail certain people should a date event be reached for a certain field. If this is possssible how would I do this.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    This level of automation is tricky. I do this by a combination of Windows Scheduled Tasks, VBScript file, and VBA code in Access.
    At specified time each day Task Manager executes VBScript
    VBScript opens Access project (in the code, substitute servername\path\filename with your values)
    Code:
    ' ProcessKillLocal.vbs
    ' Sample VBScript to kill a program
    ' Author Guy Thomas http://computerperformance.co.uk/
    ' Version 2.7 - December 2010
    ' ------------------------ -------------------------------' 
    Option Explicit
    Dim objWMIService, objProcess, colProcess
    Dim strComputer, strProcessKill 
    strComputer = "."
    strProcessKill = "'msaccess.exe'" 
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
    Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = " & strProcessKill )
    For Each objProcess in colProcess
     objProcess.Terminate()
    Next 
    'WSCript.Echo "Just killed process " & strProcessKill & " on " & strComputer
    'WScript.Quit 
    'End of WMI Example of a Kill Process 
     
    Dim objFSO, oShell
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    'open the Access file
    Set oShell = CreateObject("WScript.Shell")
    oShell.Run """C:\Program Files\Microsoft Office\Office12\msaccess.exe"" ""\\servername\path\filename.accdb""
    VBA code behind default form checks current date meets conditions, if it does, procedure is called and email is sent
    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
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    The only way I've been able to do this is via Outlook, and only in specific cases. You would first have to put some code into Outlook to bypass the security "feature" (more like pain in my ass) that wont let an email be sent by code. Further, Outlook has to be open and logged in (meaning you cant do this as a nightly batch job).

    I've seen posts on the web that attempt to this via SMTP like through a gmail account. However, I've never seen any of these actually work. If using Outlook will suffice, follow the instructions here. I use this and can vouche for it.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    My process does require Outlook but did nothing special with Outlook, no coding. Does require that my computer be on and probably logged on. I just lock my computer every night, never log off. I usually leave Outlook open but think the code runs even if Outlook closed. Will have to test that again. In the code, substitute servername\path\filename with your values.
    Code:
    Public Sub ConstructionExtract()
    'exports data to ConstructionExtract Access file
    'copies file to zip folder
    'opens Outlook and attaches file to msg and sends
    Dim strZip As String
    Dim strExtract As String
    Dim Catalog As Object
    strZip = "\\servername\path\filename.zip"
    strExtract = "\\servername\path\filename.accdb"
    'create new database
    Set Catalog = CreateObject("ADOX.Catalog")
    Catalog.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strExtract & ";"
    Set Catalog = Nothing
    'import tables to the ConstructionExtract Access file
    DoCmd.SetWarnings False
    DoCmd.RunSQL "SELECT * INTO Bituminous IN '" & strExtract & "' FROM ConstructionBIT;"
    DoCmd.RunSQL "SELECT * INTO BituminousMD IN '" & strExtract & "' FROM ConstructionBMD;"
    DoCmd.RunSQL "SELECT * INTO Concrete IN '" & strExtract & "' FROM ConstructionCONC"
    DoCmd.RunSQL "SELECT * INTO Emulsion IN '" & strExtract & "' FROM ConstructionEMUL;"
    DoCmd.RunSQL "SELECT * INTO PGAsphalt IN '" & strExtract & "' FROM ConstructionPG;"
    DoCmd.RunSQL "SELECT * INTO SoilsAgg IN '" & strExtract & "' FROM ConstructionSA;"
    DoCmd.RunSQL "SELECT * INTO SampleInfo IN '" & strExtract & "' FROM ConstructionSampleInfo;"
    DoCmd.SetWarnings True
    'create empty zip folder
    'found this on web, no idea what the Print line does but if it isn't there, this won't work
    Open strZip For Output As #1
    Print #1, "PK" & Chr$(5) & Chr$(6) & String(18, 0)
    Close #1
    'copy file into zip folder
    Dim objApp As Object
    Set objApp = CreateObject("Shell.Application")
    'variable for source file doesn't seem to work in this line
    'also double parens not in original code but won't work without
    objApp.Namespace((strZip)).CopyHere "\\servername\path\filename.accdb"
    'open Outlook, attach zip folder, send e-mail
    Dim appOutLook As Outlook.Application
    Dim MailOutLook As Outlook.MailItem
    Set appOutLook = CreateObject("Outlook.Application")
    Set MailOutLook = appOutLook.CreateItem(olMailItem)
    With MailOutLook
    .BodyFormat = olFormatRichText
    .To = "email address here"
    ''.cc = ""
    ''.bcc = ""
    .Subject = "text here"
    .HTMLBody = "text here"
    .Attachments.add (strZip)
    ''.DeleteAfterSubmit = True 'This would let Outlook send the note without storing it in your sent bin
    .send
    End With
    'delete zip folder and ConstructionExtract.accdb
    Kill strZip
    Kill strExtract
    DoCmd.SetWarnings False
    DoCmd.RunSQL "UPDATE Updates SET ConstructionExtract=#" & Date & "#"
    DoCmd.SetWarnings True
    End Sub
    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.

  5. #5
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    How do you bypass the Outlook security? With automation, I've always run across this


    without the code to bypass it.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    It's been months since I set this up. I don't remember dealing with that. Other than setting the VBA Reference, which I should have mentioned earlier, to Microsoft Outlook 12.0 Object Library.

    Even the Outlook Trust Center is set to "Warnings for signed macros; all unsigned macros are disabled." which I believe is the default.

    I know it is working. One went out yesterday. I have copy in my Outlook sent folder and the receiver has confirmed previous transmissions.
    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: 1
    Last Post: 07-27-2010, 07:06 AM
  2. Mail Merge
    By Nixx1401 in forum Access
    Replies: 1
    Last Post: 02-15-2010, 10:51 AM
  3. HTML E-mail Using VBA
    By graviz in forum Programming
    Replies: 1
    Last Post: 12-09-2009, 08:52 AM
  4. Replies: 21
    Last Post: 06-03-2009, 05:54 PM
  5. E-mail Reports
    By Mike Cooper in forum Reports
    Replies: 2
    Last Post: 08-04-2008, 12:58 AM

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