Send email using addresses in query

G

Guest

Hi all.

I want to be able to send an email to a selection within my contact
database, and to aviod having to enter all the email addressess all the time,
or have to keep a seperate address book in Microsoft Outlook, I am wanting to
be able to push a button on a form, and have a blank email come up with all
the email addresses in my contact list within the database.
The database is used on a small network, where all users have their own
address book anyway with Outlook Express or Microsoft Outlook.
I have filtered out what addresses I want using a query, but I want all
those addresses to go into the TO: box in the email.

I have been playing with this:
Dim stLinkCriteria As String
stLinkCriteria = qryEmailRec.Number
DoCmd.SendObject , , stLinkCriteria
Where stLinkCriteria is in the [TO:] position, and points to the query with
the addresses. It doesnt work, and I get the error "Object Required"

Any ideas?

Thanks in advance.
 
A

Arvin Meyer [MVP]

This will gather them up for you. Alter it to put the list into your To
field instead of the debug window. rstEmail is the name of the email field
in your query (aircode, no error handling):

Function Foo()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strTo As String
Dim i As Integer

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

With rst
If .RecordCount > 0 Then
.MoveLast
.MoveFirst
End If
End With

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

Debug.Print strTo

End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
G

Guest

Thanks. I am a little new to the flash code like this. This is what I now
have.
On my Button, I have this to open the email, and run the function:
______________________________
Dim stLinkCriteria As String
stLinkCriteria = ToEmail
DoCmd.SendObject , , stLinkCriteria
===========================
And I have my Function in the Global Code:
______________________________
Function ToEmail()

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strTo As String
Dim i As Integer

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

With rst
If .RecordCount > 0 Then
.MoveLast
.MoveFirst
End If
End With

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

Debug.Print strTo

End Function
========================

What part to I need to change to make it populate the TO: field. At the
moment I just get a blank email with no email addresses in it. The field in
the query is called "Number"

Thanks Heaps.

Arvin Meyer said:
This will gather them up for you. Alter it to put the list into your To
field instead of the debug window. rstEmail is the name of the email field
in your query (aircode, no error handling):

Function Foo()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strTo As String
Dim i As Integer

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

With rst
If .RecordCount > 0 Then
.MoveLast
.MoveFirst
End If
End With

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

Debug.Print strTo

End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access

azza said:
Hi all.

I want to be able to send an email to a selection within my contact
database, and to aviod having to enter all the email addressess all the
time,
or have to keep a seperate address book in Microsoft Outlook, I am wanting
to
be able to push a button on a form, and have a blank email come up with
all
the email addresses in my contact list within the database.
The database is used on a small network, where all users have their own
address book anyway with Outlook Express or Microsoft Outlook.
I have filtered out what addresses I want using a query, but I want all
those addresses to go into the TO: box in the email.

I have been playing with this:
Dim stLinkCriteria As String
stLinkCriteria = qryEmailRec.Number
DoCmd.SendObject , , stLinkCriteria
Where stLinkCriteria is in the [TO:] position, and points to the query
with
the addresses. It doesnt work, and I get the error "Object Required"

Any ideas?

Thanks in advance.
 
G

Guest

Never Mind, I have got it working. Code now looks like this, all attached to
a button.
Thanks heaps for your help.
--------------------------------------------
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strTo As String
Dim i As Integer

Dim stLinkCriteria As String

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

With rst
If .RecordCount > 0 Then
.MoveLast
.MoveFirst
End If
End With

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

DoCmd.SendObject acSendNoObject, , , strTo
__________________________________________

azza said:
Thanks. I am a little new to the flash code like this. This is what I now
have.
On my Button, I have this to open the email, and run the function:
______________________________
Dim stLinkCriteria As String
stLinkCriteria = ToEmail
DoCmd.SendObject , , stLinkCriteria
===========================
And I have my Function in the Global Code:
______________________________
Function ToEmail()

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strTo As String
Dim i As Integer

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

With rst
If .RecordCount > 0 Then
.MoveLast
.MoveFirst
End If
End With

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

Debug.Print strTo

End Function
========================

What part to I need to change to make it populate the TO: field. At the
moment I just get a blank email with no email addresses in it. The field in
the query is called "Number"

Thanks Heaps.

Arvin Meyer said:
This will gather them up for you. Alter it to put the list into your To
field instead of the debug window. rstEmail is the name of the email field
in your query (aircode, no error handling):

Function Foo()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strTo As String
Dim i As Integer

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

With rst
If .RecordCount > 0 Then
.MoveLast
.MoveFirst
End If
End With

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

Debug.Print strTo

End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access

azza said:
Hi all.

I want to be able to send an email to a selection within my contact
database, and to aviod having to enter all the email addressess all the
time,
or have to keep a seperate address book in Microsoft Outlook, I am wanting
to
be able to push a button on a form, and have a blank email come up with
all
the email addresses in my contact list within the database.
The database is used on a small network, where all users have their own
address book anyway with Outlook Express or Microsoft Outlook.
I have filtered out what addresses I want using a query, but I want all
those addresses to go into the TO: box in the email.

I have been playing with this:
Dim stLinkCriteria As String
stLinkCriteria = qryEmailRec.Number
DoCmd.SendObject , , stLinkCriteria
Where stLinkCriteria is in the [TO:] position, and points to the query
with
the addresses. It doesnt work, and I get the error "Object Required"

Any ideas?

Thanks in advance.
 
A

Arvin Meyer [MVP]

strTo is the string which goes in the To field of your email client. If you
use some code like:

DoCmd.SendObject , , , strTo

Put that line in place of the debug.print line

You may need some of the other arguments of SendObject
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access

azza said:
Thanks. I am a little new to the flash code like this. This is what I
now
have.
On my Button, I have this to open the email, and run the function:
______________________________
Dim stLinkCriteria As String
stLinkCriteria = ToEmail
DoCmd.SendObject , , stLinkCriteria
===========================
And I have my Function in the Global Code:
______________________________
Function ToEmail()

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strTo As String
Dim i As Integer

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

With rst
If .RecordCount > 0 Then
.MoveLast
.MoveFirst
End If
End With

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

Debug.Print strTo

End Function
========================

What part to I need to change to make it populate the TO: field. At the
moment I just get a blank email with no email addresses in it. The field
in
the query is called "Number"

Thanks Heaps.

Arvin Meyer said:
This will gather them up for you. Alter it to put the list into your To
field instead of the debug window. rstEmail is the name of the email
field
in your query (aircode, no error handling):

Function Foo()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strTo As String
Dim i As Integer

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

With rst
If .RecordCount > 0 Then
.MoveLast
.MoveFirst
End If
End With

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

Debug.Print strTo

End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access

azza said:
Hi all.

I want to be able to send an email to a selection within my contact
database, and to aviod having to enter all the email addressess all the
time,
or have to keep a seperate address book in Microsoft Outlook, I am
wanting
to
be able to push a button on a form, and have a blank email come up with
all
the email addresses in my contact list within the database.
The database is used on a small network, where all users have their own
address book anyway with Outlook Express or Microsoft Outlook.
I have filtered out what addresses I want using a query, but I want all
those addresses to go into the TO: box in the email.

I have been playing with this:
Dim stLinkCriteria As String
stLinkCriteria = qryEmailRec.Number
DoCmd.SendObject , , stLinkCriteria
Where stLinkCriteria is in the [TO:] position, and points to the query
with
the addresses. It doesnt work, and I get the error "Object Required"

Any ideas?

Thanks in advance.
 

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