loop through continuous forms

K

KathyB

I have a query which returns my data in continuous forms format.
Each of the forms has an e-mail address
I would like to be able to e-mail a report to each person listed on the forms.

I am using the following code which creates an e-mail to the person on the
first form (where 'mail' is the field name):
DoCmd.SendObject acReport, stDocName, To:=mail

Please could someone advise if it is possible to loop through all the forms
and include all the e-mail addresses on the same e-mail
 
K

Klatuu

As I am sure you know, they way you include multiple receipients in an email
is to separate the addresses with a semicolon. This is what you need to do.

You don't loop through the form, but use the form's recordset clone to build
the string, then send the email. Here is an example:

Dim strAddrList As String

With Me.RecordsetClone
.MoveLast
.MoveFirst
Do While Not .EOF
If Len(strAddrList) > 0 Then
strAddrList = strAddrList & "; "
End If
strAddrList = strAddrList & ![EmailAddress]
End Do
End With
 
K

KathyB

Many thanks for this, however it doesn't like the 'End Do' I get a compile
error : Expected : If or Select or Sub or Function or Property or Type or
With or Enum or end statement.
Would be grateful if you can advise whats wrong.


Klatuu said:
As I am sure you know, they way you include multiple receipients in an email
is to separate the addresses with a semicolon. This is what you need to do.

You don't loop through the form, but use the form's recordset clone to build
the string, then send the email. Here is an example:

Dim strAddrList As String

With Me.RecordsetClone
.MoveLast
.MoveFirst
Do While Not .EOF
If Len(strAddrList) > 0 Then
strAddrList = strAddrList & "; "
End If
strAddrList = strAddrList & ![EmailAddress]
End Do
End With

--
Dave Hargis, Microsoft Access MVP


KathyB said:
I have a query which returns my data in continuous forms format.
Each of the forms has an e-mail address
I would like to be able to e-mail a report to each person listed on the forms.

I am using the following code which creates an e-mail to the person on the
first form (where 'mail' is the field name):
DoCmd.SendObject acReport, stDocName, To:=mail

Please could someone advise if it is possible to loop through all the forms
and include all the e-mail addresses on the same e-mail
 
K

Klatuu

Sorry about that. Don't know what I was thinking. Not only did I use a
statement from another version of BASIC, I left out a very important line.
Had it worked at all, it would hang in an endless loop. Notice the addition
of the MoveNext statement:

Dim strAddrList As String
With Me.RecordsetClone
.MoveLast
.MoveFirst
Do While Not .EOF
If Len(strAddrList) > 0 Then
strAddrList = strAddrList & "; "
End If
strAddrList = strAddrList & ![EmailAddress]
.MoveNext
Loop
End With

This works, I tested it.

--
Dave Hargis, Microsoft Access MVP


KathyB said:
Many thanks for this, however it doesn't like the 'End Do' I get a compile
error : Expected : If or Select or Sub or Function or Property or Type or
With or Enum or end statement.
Would be grateful if you can advise whats wrong.


Klatuu said:
As I am sure you know, they way you include multiple receipients in an email
is to separate the addresses with a semicolon. This is what you need to do.

You don't loop through the form, but use the form's recordset clone to build
the string, then send the email. Here is an example:

Dim strAddrList As String

With Me.RecordsetClone
.MoveLast
.MoveFirst
Do While Not .EOF
If Len(strAddrList) > 0 Then
strAddrList = strAddrList & "; "
End If
strAddrList = strAddrList & ![EmailAddress]
End Do
End With

--
Dave Hargis, Microsoft Access MVP


KathyB said:
I have a query which returns my data in continuous forms format.
Each of the forms has an e-mail address
I would like to be able to e-mail a report to each person listed on the forms.

I am using the following code which creates an e-mail to the person on the
first form (where 'mail' is the field name):
DoCmd.SendObject acReport, stDocName, To:=mail

Please could someone advise if it is possible to loop through all the forms
and include all the e-mail addresses on the same e-mail
 
K

KathyB

Sorry I still can't get this to work. I really appreciate this help. The code
you gave me does not open outlook and add the recipients....
Do I still need to add my original code that only sent the mail to the first
person on the list? and if so, where does it need to go in relation to your
code? I tried everything I could think of

My code is :
Dim stDocName As String
Dim StrSubject As String
Dim StrTo As String
stDocName = "outstanding_tasks"
DoCmd.SendObject acReport, stDocName, To:=mail

As you can tell I am no VBA expert!

Klatuu said:
Sorry about that. Don't know what I was thinking. Not only did I use a
statement from another version of BASIC, I left out a very important line.
Had it worked at all, it would hang in an endless loop. Notice the addition
of the MoveNext statement:

Dim strAddrList As String
With Me.RecordsetClone
.MoveLast
.MoveFirst
Do While Not .EOF
If Len(strAddrList) > 0 Then
strAddrList = strAddrList & "; "
End If
strAddrList = strAddrList & ![EmailAddress]
.MoveNext
Loop
End With

This works, I tested it.

--
Dave Hargis, Microsoft Access MVP


KathyB said:
Many thanks for this, however it doesn't like the 'End Do' I get a compile
error : Expected : If or Select or Sub or Function or Property or Type or
With or Enum or end statement.
Would be grateful if you can advise whats wrong.


Klatuu said:
As I am sure you know, they way you include multiple receipients in an email
is to separate the addresses with a semicolon. This is what you need to do.

You don't loop through the form, but use the form's recordset clone to build
the string, then send the email. Here is an example:

Dim strAddrList As String

With Me.RecordsetClone
.MoveLast
.MoveFirst
Do While Not .EOF
If Len(strAddrList) > 0 Then
strAddrList = strAddrList & "; "
End If
strAddrList = strAddrList & ![EmailAddress]
End Do
End With

--
Dave Hargis, Microsoft Access MVP


:

I have a query which returns my data in continuous forms format.
Each of the forms has an e-mail address
I would like to be able to e-mail a report to each person listed on the forms.

I am using the following code which creates an e-mail to the person on the
first form (where 'mail' is the field name):
DoCmd.SendObject acReport, stDocName, To:=mail

Please could someone advise if it is possible to loop through all the forms
and include all the e-mail addresses on the same e-mail
 
K

Klatuu

The code I sent does not open Outlook. The SendObject method sends the
message to Outlook, but you will not see Outlook open.

This line:
DoCmd.SendObject acReport, stDocName, To:=mail

is mixing argument passing. if you are goint to use a named argument as you
are in To:=mail, you need to use named arguments for all the arguments, or
you need to use the arguments in their position. Try this:

DoCmd.SendObject acReport, strDocName, , mail

But, I don't see where mail is dimmed or used. if it is the variable you use
to contain the list of receipients, then you need to be sure the variable is
in scope. That is, where it is dimmed. If the sub or function where mail is
dimmed, then you should be okay. If they are in different subs or functions,
then you need to dim the variable at the form level.

--
Dave Hargis, Microsoft Access MVP


KathyB said:
Sorry I still can't get this to work. I really appreciate this help. The code
you gave me does not open outlook and add the recipients....
Do I still need to add my original code that only sent the mail to the first
person on the list? and if so, where does it need to go in relation to your
code? I tried everything I could think of

My code is :
Dim stDocName As String
Dim StrSubject As String
Dim StrTo As String
stDocName = "outstanding_tasks"
DoCmd.SendObject acReport, stDocName, To:=mail

As you can tell I am no VBA expert!

Klatuu said:
Sorry about that. Don't know what I was thinking. Not only did I use a
statement from another version of BASIC, I left out a very important line.
Had it worked at all, it would hang in an endless loop. Notice the addition
of the MoveNext statement:

Dim strAddrList As String
With Me.RecordsetClone
.MoveLast
.MoveFirst
Do While Not .EOF
If Len(strAddrList) > 0 Then
strAddrList = strAddrList & "; "
End If
strAddrList = strAddrList & ![EmailAddress]
.MoveNext
Loop
End With

This works, I tested it.

--
Dave Hargis, Microsoft Access MVP


KathyB said:
Many thanks for this, however it doesn't like the 'End Do' I get a compile
error : Expected : If or Select or Sub or Function or Property or Type or
With or Enum or end statement.
Would be grateful if you can advise whats wrong.


:

As I am sure you know, they way you include multiple receipients in an email
is to separate the addresses with a semicolon. This is what you need to do.

You don't loop through the form, but use the form's recordset clone to build
the string, then send the email. Here is an example:

Dim strAddrList As String

With Me.RecordsetClone
.MoveLast
.MoveFirst
Do While Not .EOF
If Len(strAddrList) > 0 Then
strAddrList = strAddrList & "; "
End If
strAddrList = strAddrList & ![EmailAddress]
End Do
End With

--
Dave Hargis, Microsoft Access MVP


:

I have a query which returns my data in continuous forms format.
Each of the forms has an e-mail address
I would like to be able to e-mail a report to each person listed on the forms.

I am using the following code which creates an e-mail to the person on the
first form (where 'mail' is the field name):
DoCmd.SendObject acReport, stDocName, To:=mail

Please could someone advise if it is possible to loop through all the forms
and include all the e-mail addresses on the same e-mail
 
K

KathyB

Thankyou very much for your help it has been most appreciated!

Klatuu said:
The code I sent does not open Outlook. The SendObject method sends the
message to Outlook, but you will not see Outlook open.

This line:
DoCmd.SendObject acReport, stDocName, To:=mail

is mixing argument passing. if you are goint to use a named argument as you
are in To:=mail, you need to use named arguments for all the arguments, or
you need to use the arguments in their position. Try this:

DoCmd.SendObject acReport, strDocName, , mail

But, I don't see where mail is dimmed or used. if it is the variable you use
to contain the list of receipients, then you need to be sure the variable is
in scope. That is, where it is dimmed. If the sub or function where mail is
dimmed, then you should be okay. If they are in different subs or functions,
then you need to dim the variable at the form level.

--
Dave Hargis, Microsoft Access MVP


KathyB said:
Sorry I still can't get this to work. I really appreciate this help. The code
you gave me does not open outlook and add the recipients....
Do I still need to add my original code that only sent the mail to the first
person on the list? and if so, where does it need to go in relation to your
code? I tried everything I could think of

My code is :
Dim stDocName As String
Dim StrSubject As String
Dim StrTo As String
stDocName = "outstanding_tasks"
DoCmd.SendObject acReport, stDocName, To:=mail

As you can tell I am no VBA expert!

Klatuu said:
Sorry about that. Don't know what I was thinking. Not only did I use a
statement from another version of BASIC, I left out a very important line.
Had it worked at all, it would hang in an endless loop. Notice the addition
of the MoveNext statement:

Dim strAddrList As String
With Me.RecordsetClone
.MoveLast
.MoveFirst
Do While Not .EOF
If Len(strAddrList) > 0 Then
strAddrList = strAddrList & "; "
End If
strAddrList = strAddrList & ![EmailAddress]
.MoveNext
Loop
End With

This works, I tested it.

--
Dave Hargis, Microsoft Access MVP


:

Many thanks for this, however it doesn't like the 'End Do' I get a compile
error : Expected : If or Select or Sub or Function or Property or Type or
With or Enum or end statement.
Would be grateful if you can advise whats wrong.


:

As I am sure you know, they way you include multiple receipients in an email
is to separate the addresses with a semicolon. This is what you need to do.

You don't loop through the form, but use the form's recordset clone to build
the string, then send the email. Here is an example:

Dim strAddrList As String

With Me.RecordsetClone
.MoveLast
.MoveFirst
Do While Not .EOF
If Len(strAddrList) > 0 Then
strAddrList = strAddrList & "; "
End If
strAddrList = strAddrList & ![EmailAddress]
End Do
End With

--
Dave Hargis, Microsoft Access MVP


:

I have a query which returns my data in continuous forms format.
Each of the forms has an e-mail address
I would like to be able to e-mail a report to each person listed on the forms.

I am using the following code which creates an e-mail to the person on the
first form (where 'mail' is the field name):
DoCmd.SendObject acReport, stDocName, To:=mail

Please could someone advise if it is possible to loop through all the forms
and include all the e-mail addresses on the same e-mail
 

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