Email Code Question

dlafko

New Member
Joined
Dec 19, 2014
Messages
43
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
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,221,905
Messages
6,162,772
Members
451,786
Latest member
CALEB23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top