473,322 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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:-

<snipped>

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

<snipped>
Dec 9 '06 #1
2 2291
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:-

<snipped>

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

<snipped>
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
Dec 9 '06 #2
Works perfect Fred - many thanks

John Taylor
Dec 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: jdph40 | last post by:
I have a form in Access 97 on which I have an unbound list box filled with our employees names from tblEmployees. When you select an employee's name and click a button, the following code is run...
1
by: Alfred | last post by:
Hi I am using access 2002 1.0 I want to email a word or html file using the docmd.sendobject The document must be send as a attachment. 2.0 Second I would like to tell the Docmd.Sendobject to...
6
by: Mr. Bungle | last post by:
I would like to send email automatically via a command button. I have accomplished this just fine through the following code: (Outlook should already be open for reliable results) Private Sub...
0
by: cronept | last post by:
Hi, there, I have a form with 2 email buttons both with docmd.sendobject code. The 1st one send a report which is working properly. The 2nd one send a query in xls format which is always get an...
3
by: Karl Roes | last post by:
Hi all, I am after some suggestions on ways to email an errorlog table. I have been working on remote interfaces and would like the users to email the errorlog back to me at the push of a button...
5
by: Mark | last post by:
Hi All, Is there a way to (whilst using the sendobject command) use a query as the source of email addresses. I ask this because the list is constanly changing and I don't want to keep going into...
6
by: Tony Ciconte | last post by:
There is plenty of VBA code around that allows you send email messages. Does anyone know where I can see a sample of VBA code or a technique that only opens the default email program and then waits...
2
by: Marcus | last post by:
Is there a way to have Access 2002 open a particular email client, when using DoCmd.SendObject? So far, Access simply opens the default email client that is set under Control Panel/Internet...
7
by: captainmorgan | last post by:
Below is the code I'm trying to use to create a blank email with the bcc list populated from a query. (1) I have tested the codes output of the "rcpts" field, and counted it as well - OK (2) I've...
2
by: Owen Mac | last post by:
Hello everyone, Is it possible to use an email address from a table and/or query with the Sendobject Method. An email address from my form works fine...what I would like is the 'To:' section be...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.