Sending Email From a Form

M

Michael

I have VBA code on an Access Form that will allow me to
send an email messge to the email addres in a field, but
is there a way, using a modification of the same code to
Send Bulk email to every email address in that field in
my database Using a Query?

I can get the code to read an email address in a single
field from a form, but could I have it retrieve all
email addresses from an external query. I want the email
address to appear ready to send from MS Outlook Express
in the Bcc: field to everyone in my Database.

Form so far:

Feild which contains email address.
On click button that opens Outlook express and places
email address in the To: CC: or Bcc: line (based on code).

code i have got so far:
______________________________________
Private Sub Email2_Click()
DoCmd.SendObject _
, _
, _
, _
("" & Me!EmailAddress), _
, _
, _
, _
, _
True
End Sub
_______________________________________
Private Sub Form_frm_Missions_Main2()
Me!Email2.Enabled = Not (IsNull(Me!EmailAddress))
End Sub

Can anyone help
 
N

nathan harrison

Hi Michael,

you have open the recordset and loop through all your records grabbing each
email address as you go. then you string them all together. here is a
sample i threw together. hope it helps give you the idea i'm talking about.

'****begin air code***
Option Compare Database
Option Explicit

Private Sub Command0_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim i As Integer
Dim rcount As Integer
Dim varMsg As String
Dim strBcc As String
Dim strBody As String

Set db = CurrentDb
Set rst = db.OpenRecordset("customers", dbOpenSnapshot)

rst.MoveLast

With rst
If .RecordCount > 0 Then
.MoveFirst
For i = 1 To .RecordCount
If Len(!E_Mail) > 0 Then
strBcc = strBcc & !E_Mail & ";"
End If
.MoveNext
Next i
strBcc = Left$(strBcc, Len(strBcc) - 1)

End If
End With

varMsg = "This is a test"

strBody = "This is the body of the email"

DoCmd.SendObject , , ,"(e-mail address removed)", , strBcc, varMsg,
strBody, True

End Sub

'****end air code*****
 
G

Guest

Using the code below, and changing "customers" to the
name of my query, I get

Compile error
User-defined type not defined

on the first line in the sub

Dim db As DAO.Database

What I'm I not understanding here??

My code is as follows
**************************************
Option Compare Database
Option Explicit
_____________________________

Private Sub Command0_Click()

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim i As Integer
Dim rcount As Integer
Dim varMsg As String
Dim strBcc As String
Dim strBody As String

Set db = CurrentDb
Set rst = db.OpenRecordset("customers",
dbOpenSnapshot)

rst.MoveLast

With rst
If .RecordCount > 0 Then
.MoveFirst
For i = 1 To .RecordCount
If Len(!E_Mail) > 0 Then
strBcc = strBcc & !E_Mail & ";"
End If
.MoveNext
Next i
strBcc = Left$(strBcc, Len(strBcc) - 1)

End If
End With

varMsg = "This is a test"

strBody = "This is the body of the email"

DoCmd.SendObject , _
, _
, _
, _
"(e-mail address removed)", _
, _
strBcc, _
varMsg, _
strBody, True

End Sub
***********************************
 
N

nathan harrison

hi michael,

in your VBA window, goto: Tools>References
look to see if you have a reference to Microsoft DAO Object Library checked.
if you do not, scroll down and check the latest version you have. 3.x
probably

that should take care it for you.

let me know if it works.

Nathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top