dbaspot
Tags Register FAQ Calendar Search Today's Posts Mark Forums Read

email using SendObject - ms-access

This is a discussion on email using SendObject - ms-access ; I have created a command button on a form that prints a filtered report and e-mails the report to three people when "clicked". The three email addresses are selected on the form by three combo boxes that populate the following ...


Home > Database Forum > Other Databases > ms-access > email using SendObject

Reply

 

LinkBack Thread Tools Display Modes
  #1  
Old 12-08-2006, 10:39 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default email using SendObject

I have created a command button on a form that prints a filtered report and
e-mails the report to three people when "clicked". The three email addresses
are selected on the form by three combo boxes that populate the following
three fields - "ContName", "ContName1" and "ContName2".

My code simply uses SendObject to print the report and select the three
e-mail addresses. However, I do not always have three recipients to send the
report to, I may only want to send the report to two recipients (therefore
the ContName2 field on the form will be empty). When this is the case I get
an error, obviously the code is looking for the third e-mail address.

I've attached the code, for your review, at the bottom of this post.

Is there any way around this - I want the code to ignore any "empty" field.

I've Googled and searched MS for a solution - I'm either missing the point
or I'm doing something terribly wrong.

Thanks in advance for any help

John Taylor

The code:-



Dim stDocName As String
Dim strReportFilter As String

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70


stDocName = "RptChangeControlMain"
strReportFilter = "ID = " & Forms!FrmChgCon!ID

DoCmd.OpenReport stDocName, acViewNormal, , strReportFilter

DoCmd.SendObject acSendReport, stDocName, "Snapshot Format",
Forms!FrmChgCon!ContName, Forms!FrmChgCon!ContName1,
Forms!FrmChgCon!ContName2, "Title - Header Description", "do something",
True




Reply With Quote
  #2  
Old 12-08-2006, 11:55 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: email using SendObject

On Sat, 9 Dec 2006 11:39:25 +0900, John Taylor wrote:

> I have created a command button on a form that prints a filtered report and
> e-mails the report to three people when "clicked". The three email addresses
> are selected on the form by three combo boxes that populate the following
> three fields - "ContName", "ContName1" and "ContName2".
>
> My code simply uses SendObject to print the report and select the three
> e-mail addresses. However, I do not always have three recipients to send the
> report to, I may only want to send the report to two recipients (therefore
> the ContName2 field on the form will be empty). When this is the case I get
> an error, obviously the code is looking for the third e-mail address.
>
> I've attached the code, for your review, at the bottom of this post.
>
> Is there any way around this - I want the code to ignore any "empty" field.
>
> I've Googled and searched MS for a solution - I'm either missing the point
> or I'm doing something terribly wrong.
>
> Thanks in advance for any help
>
> John Taylor
>
> The code:-
>
>
>
> Dim stDocName As String
> Dim strReportFilter As String
>
> DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
>
> stDocName = "RptChangeControlMain"
> strReportFilter = "ID = " & Forms!FrmChgCon!ID
>
> DoCmd.OpenReport stDocName, acViewNormal, , strReportFilter
>
> DoCmd.SendObject acSendReport, stDocName, "Snapshot Format",
> Forms!FrmChgCon!ContName, Forms!FrmChgCon!ContName1,
> Forms!FrmChgCon!ContName2, "Title - Header Description", "do something",
> True
>
>


Does this work?

Dim strSendTo as String
strSendTo = (Trim(Forms!FrmChgCon!ContName) + ",") &
(Trim(Forms!FrmChgCon!ContName1) + ",") &
Trim(Forms!FrmChgCon!ContName2)

If Right(strSendTo, 1) = "," Then
strSendTo = Left(strSendTo, Len(strSendTo) - 1)
End If

stDocName = "RptChangeControlMain"
strReportFilter = "ID = " & Forms!FrmChgCon!ID

DoCmd.OpenReport stDocName, acViewNormal, , strReportFilter

DoCmd.SendObject acSendReport, stDocName, "Snapshot Format",
strSendTo, "Title - Header Description", "do something",
True

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Reply With Quote
  #3  
Old 12-08-2006, 11:55 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: email using SendObject

On Sat, 9 Dec 2006 11:39:25 +0900, John Taylor wrote:

> I have created a command button on a form that prints a filtered report and
> e-mails the report to three people when "clicked". The three email addresses
> are selected on the form by three combo boxes that populate the following
> three fields - "ContName", "ContName1" and "ContName2".
>
> My code simply uses SendObject to print the report and select the three
> e-mail addresses. However, I do not always have three recipients to send the
> report to, I may only want to send the report to two recipients (therefore
> the ContName2 field on the form will be empty). When this is the case I get
> an error, obviously the code is looking for the third e-mail address.
>
> I've attached the code, for your review, at the bottom of this post.
>
> Is there any way around this - I want the code to ignore any "empty" field.
>
> I've Googled and searched MS for a solution - I'm either missing the point
> or I'm doing something terribly wrong.
>
> Thanks in advance for any help
>
> John Taylor
>
> The code:-
>
>
>
> Dim stDocName As String
> Dim strReportFilter As String
>
> DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
>
> stDocName = "RptChangeControlMain"
> strReportFilter = "ID = " & Forms!FrmChgCon!ID
>
> DoCmd.OpenReport stDocName, acViewNormal, , strReportFilter
>
> DoCmd.SendObject acSendReport, stDocName, "Snapshot Format",
> Forms!FrmChgCon!ContName, Forms!FrmChgCon!ContName1,
> Forms!FrmChgCon!ContName2, "Title - Header Description", "do something",
> True
>
>


Does this work?

Dim strSendTo as String
strSendTo = (Trim(Forms!FrmChgCon!ContName) + ",") &
(Trim(Forms!FrmChgCon!ContName1) + ",") &
Trim(Forms!FrmChgCon!ContName2)

If Right(strSendTo, 1) = "," Then
strSendTo = Left(strSendTo, Len(strSendTo) - 1)
End If

stDocName = "RptChangeControlMain"
strReportFilter = "ID = " & Forms!FrmChgCon!ID

DoCmd.OpenReport stDocName, acViewNormal, , strReportFilter

DoCmd.SendObject acSendReport, stDocName, "Snapshot Format",
strSendTo, "Title - Header Description", "do something",
True

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Reply With Quote
  #4  
Old 12-09-2006, 12:44 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: email using SendObject

Works perfect Fred - many thanks

John Taylor


Reply With Quote
  #5  
Old 12-09-2006, 12:44 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: email using SendObject

Works perfect Fred - many thanks

John Taylor


Reply With Quote
Reply

Thread Tools
Display Modes



All times are GMT -4. The time now is 11:49 AM.