VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



E-mail Access Reports

by Miyagi (1 Submission)
Category: Microsoft Office Apps/VBA
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

Allows you to use Outlook to send bulk e-mails of Access Reports in Snapshot Format to users (ISO Printing, Faxing etc...)

Inputs
Uses an Access Database with User e-mail adresses Used DAO, thus you need to set a Reference in Outlook to the MS DAO 3.51 Library
Assumes
This code should go in an Oulook module. You can then run the code by itself or by creating a menuitem on your menus. This would also require you to first save your files as Snapshot files in a specified direcory. You can of course do this in one step but we needed to send 6 files. That would have meant six e-mails, we prefferred to send 1 only and hence the effort to first create the files
Side Effects
No Error Trapping.

Rate E-mail Access Reports

'Option Explicit
Public Sub MailToUsers()
  Dim myOlApp As Application
  Dim myItem As MailItem
  Dim Path As String
  Dim myAttachments As Attachments
  Dim db As Database
  Dim rs As Recordset
  Dim BodyMsg As String
  
  On Error GoTo myErr
    
  'Set Database and Path to use to use
  Set db = OpenDatabase("z:\DatabasePath\dbDatabaseName.mdb")
   
  'Set Path to where Files are located
  Path = "z:\SnapshotFilesPath\"
  'Set Value for Body Message
  BodyMsg = "Type whatever bodymessage you might need"
  'Set Recordset to Users Table
  Set rs = db.OpenRecordset("tblUsers")
  
  'Open or use Outlook
  Set myOlApp = CreateObject("Outlook.Application")
  
  rs.MoveLast
  rs.MoveFirst
  
  Do Until rs.EOF
  
    'Creates a new Outlook MailItem
    Set myItem = myOlApp.CreateItem(olMailItem)
    With myItem
      .To = rs.Fields("[Email]")
      .Subject = "Supply your subject line here"
      .Body = BodyMsg
    End With
            
    'This Creates an Outlook attachment  
    Set myAttachments = myItem.Attachments
    With myAttachments
      'Do for all reports
      .Add Path & "\rptReport1.snp"
      .Add Path & "\rptReport2.snp"    
  
      '************************************
      'Additional Documents can be added
      'Supply full Path and File Name
      
      '.Add "c:\moc\Questionnaire Script Changes for Dealer Reports 2000_03.doc"
      '************************************
    
    'Use myItem.Save ISO myItem.Send to view before sending
    'myItem.Save
    myItem.Send
    End With
    
    'Go to the next user
    rs.MoveNext
    
  Loop
    
  Set myOlApp = Nothing
  Set rs = Nothing
  Set db = Nothing
  Exit Sub
  
myErr:
  Resume Next
End Sub

Download this snippet    Add to My Saved Code

E-mail Access Reports Comments

No comments have been posted about E-mail Access Reports. Why not be the first to post a comment about E-mail Access Reports.

Post your comment

Subject:
Message:
0/1000 characters