I have 2 sets of code one for Command1 Click which I want to BCC all the email addresses in the database and then I have an EmailAdmin Click which is only suppose to email that people who are admins, Which it does.
The question is, How do I get the Admin to email in the CC it only seems to change when I change the command1 code which obviously I don't want to so. I not being very good at code maybe messed something up so the code below is all the code comman1 and admin. If they are tied together how do I separate them so they act independent of each other. Thanks for your help
Option Compare Database
Private Sub Command1_Click()
Dim myEmailString As String
Dim x As Integer
Dim db As Database
Dim rstEmails As Recordset
Set db = CurrentDb()
Set rstEmails = db.OpenRecordset("SELECT * FROM PCOMAIN;", dbOpenSnapshot)
Do While Not rstEmails.EOF
myEmailString = myEmailString & "; " & rstEmails.Fields("Email").Value
rstEmails.MoveNext
Loop
SendEmailFinal myEmailString, " ", " ", " "
End Sub
Sub SendEmailFinal(EmailBCC As String, EmailCC As String, EmailSubject As String, EmailBody As String)
Dim olApp As Object
Dim olItem As Object
Set olApp = CreateObject("Outlook.Application")
Set olItem = olApp.createitem(0)
With olItem
.To = "david@djlprinting.com"
.CC = EmailCC
.BCC = EmailBCC
.Subject = EmailSubject
.BodyFormat = 2
.HTMLBody = EmailBody
End With
SendEmail:
olItem.Display 'display the email instead of sending it.
Set olApp = Nothing
Set olItem = Nothing
End Sub
Private Sub EmailAdmin_Click()
Dim myEmailString As String
Dim x As Integer
Dim db As Database
Dim rstEmails As Recordset
Set db = CurrentDb()
Set rstEmails = db.OpenRecordset("SELECT * FROM admin;", dbOpenSnapshot)
Do While Not rstEmails.EOF
myEmailString = myEmailString & "; " & rstEmails.Fields("Email").Value
rstEmails.MoveNext
Loop
SendEmailFinal myEmailString, " ", " ", " "
End Sub
Sub SendEmailFinaladmin(EmailTO As String, EmailCC As String, EmailSubject As String, EmailBody As String)
Dim olApp As Object
Dim olItem As Object
Set olApp = CreateObject("Outlook.Application")
Set olItem = olApp.createitem(0)
With olItem
.To = EmailTO
.CC = EmailCC
.BCC = EmailBCC
.Subject = EmailSubject
.BodyFormat = 2
.HTMLBody = EmailBody
End With
SendEmail:
olItem.Display 'display the email instead of sending it.
Set olApp = Nothing
Set olItem = Nothing
End Sub
The question is, How do I get the Admin to email in the CC it only seems to change when I change the command1 code which obviously I don't want to so. I not being very good at code maybe messed something up so the code below is all the code comman1 and admin. If they are tied together how do I separate them so they act independent of each other. Thanks for your help
Option Compare Database
Private Sub Command1_Click()
Dim myEmailString As String
Dim x As Integer
Dim db As Database
Dim rstEmails As Recordset
Set db = CurrentDb()
Set rstEmails = db.OpenRecordset("SELECT * FROM PCOMAIN;", dbOpenSnapshot)
Do While Not rstEmails.EOF
myEmailString = myEmailString & "; " & rstEmails.Fields("Email").Value
rstEmails.MoveNext
Loop
SendEmailFinal myEmailString, " ", " ", " "
End Sub
Sub SendEmailFinal(EmailBCC As String, EmailCC As String, EmailSubject As String, EmailBody As String)
Dim olApp As Object
Dim olItem As Object
Set olApp = CreateObject("Outlook.Application")
Set olItem = olApp.createitem(0)
With olItem
.To = "david@djlprinting.com"
.CC = EmailCC
.BCC = EmailBCC
.Subject = EmailSubject
.BodyFormat = 2
.HTMLBody = EmailBody
End With
SendEmail:
olItem.Display 'display the email instead of sending it.
Set olApp = Nothing
Set olItem = Nothing
End Sub
Private Sub EmailAdmin_Click()
Dim myEmailString As String
Dim x As Integer
Dim db As Database
Dim rstEmails As Recordset
Set db = CurrentDb()
Set rstEmails = db.OpenRecordset("SELECT * FROM admin;", dbOpenSnapshot)
Do While Not rstEmails.EOF
myEmailString = myEmailString & "; " & rstEmails.Fields("Email").Value
rstEmails.MoveNext
Loop
SendEmailFinal myEmailString, " ", " ", " "
End Sub
Sub SendEmailFinaladmin(EmailTO As String, EmailCC As String, EmailSubject As String, EmailBody As String)
Dim olApp As Object
Dim olItem As Object
Set olApp = CreateObject("Outlook.Application")
Set olItem = olApp.createitem(0)
With olItem
.To = EmailTO
.CC = EmailCC
.BCC = EmailBCC
.Subject = EmailSubject
.BodyFormat = 2
.HTMLBody = EmailBody
End With
SendEmail:
olItem.Display 'display the email instead of sending it.
Set olApp = Nothing
Set olItem = Nothing
End Sub