Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 884
  • Last Modified:

Email to all contacts in Access Database

This question might be a little difficult and I have totally no idea how to do, please show me step by step if possible (I never done this before)
   How do I do if I want to send a email to all the people that I have in my database at the same time from a gmail account.  for example, right now I only have two people in the DB, but I will be adding more in the future, I want to go to my gmail account and send an email to everyone and I don't want to send one by one, is anyway to do that?  That I can do from my gmail and select all the email address from my database?  I attach my DB too
AFSCME.mdb
0
urjudo
Asked:
urjudo
  • 6
  • 4
  • 2
2 Solutions
 
COACHMAN99Commented:
you can write vba code in the database to send emails to whoever you want.
0
 
urjudoAuthor Commented:
where I can start? do you have any example?
0
 
COACHMAN99Commented:
coding the whole app will take me too much time unfortunately, but the key functions are

you will need to add a reference to the Outlook object library - tools/references in the vba window.

Function SendEmail(RecipEmail As String, Subject As String, BBody As String, cc1 As String) As Boolean
  On Error GoTo err_SendEmail
  Dim olApp As Outlook.Application
  Dim oItem As Outlook.MailItem
  Dim tInterval As Integer, signature As String
  If RecipEmail <> "" Then
    SendEmail = False
    Set olApp = CreateObject("Outlook.Application")
    Set oItem = olApp.CreateItem(olMailItem)
    With oItem
      .To = RecipEmail & IIf(cc1 <> "", "; " & cc1, "")
      .Display   'to get signature for later use
      signature = Nz(DLookup("CurricCoordSignature", "tblPrograms_LOOKUP", "Prog_Num=" & Nz(Forms("frmMain").cboProgram, 0)), 0) '.Body
      .Subject = Subject
      .Body = BBody & vbCr & vbCr & signature
    End With
    If Nz(gAttach1, "") <> "" Then oItem.Attachments.Add (cAttachmentPath & gAttach1)
    oItem.Display

  End If
  SendEmail = True
exit_SendEmail:
  On Error Resume Next
  Set olApp = Nothing
  Set oItem = Nothing
  Exit Function
err_SendEmail:
  MsgBox "Error " & Err.Number & ", " & Err.Description & " Occurred in SendEmail after " & ErrorLine
  Resume exit_SendEmail
End Function
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
MacroShadowCommented:
I prefer CDO. Attached please find a sample.
AFSCME.mdb
0
 
urjudoAuthor Commented:
Hi Marcoshadow,  
Thank you so much for the example, but when I made change for the code such as add my real gmail address, password, it seems when I click the send email button, it does not do anything, may be I need to check any of the References?
0
 
MacroShadowCommented:
No need for references. Try placing a break point in the beginning of the code and step thru it, that way you can see what's happening.
0
 
urjudoAuthor Commented:
it stops at If rs.BOF <> rs.EOF, the error message is "re.EOF =<object variable or with block variable not set>"
0
 
MacroShadowCommented:
1. there is a typo: re.EOF instead of rs.EOF
2. add
rs.movelast
rs.movefirst

Open in new window


before the line that errs out.
0
 
urjudoAuthor Commented:
for some reason, it seems the button is still not doing anything  after i added the two lines and fixed the code, do i need to  change anything in the modules? such as the "username" & "password"?
0
 
MacroShadowCommented:
Is there an error, if so, which and where?
0
 
urjudoAuthor Commented:
it still stop on the if rs.bof<>rs.eof , the same message that i mentioned before, even i already put my gmail address and password, that's i was wandering if i need to change anything in the module that states "username"and "password" to be the same as i have in the send email button code?
0
 
urjudoAuthor Commented:
Thank you!!!!
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

  • 6
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now