Naming E-Mail Attachment

D

Dwayne Conyers

In the code segment below, we create an RTF file from a dB query and attach
it to an e-mail. We would like to give the attachment a dynamic name (e.g.,
the variable "foobar") but the SendObject action doesn't support naming...
unless we are misreading the arguments. How can we attach a name to the
object?

<!--

Private Sub Combo7_BeforeUpdate(Cancel As Integer)
On Error Resume Next

foo = Combo7.Value
bar = Combo7.Text
foobar = Trim(bar) & ".doc"

newSQL = "SELECT Report_Types.report_type, Agency_Codes.Agency_Code,
[DHS Reports].Report_Number, classification.classification, [DHS
Reports].Subject, [DHS Reports].Reference, [DHS Reports].Source_Descriptor,
[DHS Reports].Summary, [DHS Reports].Detail, [DHS Reports].Significance,
[DHS Reports].Actions_FU, [DHS Reports].Miscellaneous, [DHS
Reports].Preparer, status.status_text, [DHS Reports].Contact, [DHS
Reports].DOI, [DHS Reports].Release, [DHS Reports].[Report Loc],
reporting.Reporting INTO temp FROM (((([DHS Reports] LEFT JOIN Report_Types
ON [DHS Reports].Report_Type_Key = Report_Types.rpt_type_id) LEFT JOIN
Agency_Codes ON [DHS Reports].Agency_Code_Key = Agency_Codes.ag_cd_id) LEFT
JOIN classification ON [DHS Reports].Classification =
classification.classID) LEFT JOIN reporting ON [DHS Reports].Reporting =
reporting.rptg_id) INNER JOIN status ON [DHS Reports].Status =
status.statusID WHERE ((([DHS Reports].ID)=" & Trim(Str(foo)) & "));"

DoCmd.RunSQL newSQL
DoCmd.SendObject acOutputReport, "e-mail", acFormatRTF, , , , bar,
foobar, True

End Sub
 
S

SA

Dwayne:

Using Send object, there is no way to specify an object name. There are a
couple of ways to do it.

1.) Use Automation with Outlook to grab the message after you create it
(search on the subject) and you can then deal with attachments.

2.) Use method to send the mail, again such as programming the Outlook
object (see the MS KB), or using another third party emailing utility to
create the mail in Outlook; there are many third party utilities out there,
including our PDF and Mail Library for Access.
 
D

Dwayne Conyers

Unfortunately, that presents more complexity than the
client will support. We won't have access to Exchange
Server and are limited in running macros in that
environment...

d.c.

-----Original Message-----
Dwayne:

Using Send object, there is no way to specify an object name. There are a
couple of ways to do it.

1.) Use Automation with Outlook to grab the message after you create it
(search on the subject) and you can then deal with attachments.

2.) Use method to send the mail, again such as programming the Outlook
object (see the MS KB), or using another third party emailing utility to
create the mail in Outlook; there are many third party utilities out there,
including our PDF and Mail Library for Access.
--
Steve Arbaugh
ACG Soft
http://ourworld.compuserve.com/homepages/attac-cg

In the code segment below, we create an RTF file from a
dB query and
attach
it to an e-mail. We would like to give the attachment
a dynamic name
(e.g.,
the variable "foobar") but the SendObject action doesn't support naming...
unless we are misreading the arguments. How can we attach a name to the
object?

<!--

Private Sub Combo7_BeforeUpdate(Cancel As Integer)
On Error Resume Next

foo = Combo7.Value
bar = Combo7.Text
foobar = Trim(bar) & ".doc"

newSQL = "SELECT Report_Types.report_type, Agency_Codes.Agency_Code,
[DHS Reports].Report_Number, classification.classification, [DHS
Reports].Subject, [DHS Reports].Reference, [DHS Reports].Source_Descriptor,
[DHS Reports].Summary, [DHS Reports].Detail, [DHS Reports].Significance,
[DHS Reports].Actions_FU, [DHS Reports].Miscellaneous, [DHS
Reports].Preparer, status.status_text, [DHS Reports].Contact, [DHS
Reports].DOI, [DHS Reports].Release, [DHS Reports]. [Report Loc],
reporting.Reporting INTO temp FROM (((([DHS Reports]
LEFT JOIN
Report_Types
ON [DHS Reports].Report_Type_Key = Report_Types.rpt_type_id) LEFT JOIN
Agency_Codes ON [DHS Reports].Agency_Code_Key =
Agency_Codes.ag_cd_id)
LEFT
JOIN classification ON [DHS Reports].Classification =
classification.classID) LEFT JOIN reporting ON [DHS Reports].Reporting =
reporting.rptg_id) INNER JOIN status ON [DHS Reports].Status =
status.statusID WHERE ((([DHS Reports].ID)=" & Trim(Str (foo)) & "));"

DoCmd.RunSQL newSQL
DoCmd.SendObject acOutputReport, "e-mail", acFormatRTF, , , , bar,
foobar, True

End Sub


.
 
A

Alick [MSFT]

Hi Dwayne,

As Steve said by using Send object, there is no way to specify an object
name, however, it seems the report attachment file name depends on its
caption property, we can change the report's caption value before we call
sendobject method, this way, the file name can be created dynamically.

The following sample code changes the report's caption dynamically:

DoCmd.OpenReport "aaa", acViewDesign

'aaa is the report name, change its caption to string "hello"
Reports("aaa").Caption = "hello"

'save the changes
DoCmd.Close acReport, "aaa", acSaveYes

'the printed file is hello.rtf
DoCmd.SendObject acSendReport, "aaa", acFormatRTF

If you would like to keep the original caption value, you can keep the
original caption value and change it back after you call sendobject method.

But this method does not change the file extension, the file extension is
controlled by the format, it seems there is no way to change the file
extension before the file is created, after the file is created, there may
be some method to change it, such as the method Steven mentioned - to
access outlook object module (if you don't have Microsoft Outlook, instead
you have Outlook Express, it is much complex to deal with Outlook Express).

Please feel free to reply to the threads if you have any concerns or
questions.



Sincerely,

Alick Ye, MCSD
Product Support Services
Microsoft Corporation
Get Secure! - <www.microsoft.com/security>

This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
| Content-Class: urn:content-classes:message
| From: "Dwayne Conyers" <[email protected]>
| Sender: "Dwayne Conyers" <[email protected]>
| X-Tomcat-NG: microsoft.public.access.reports
|
| Unfortunately, that presents more complexity than the
| client will support. We won't have access to Exchange
| Server and are limited in running macros in that
| environment...
|
| d.c.
|
|
| >-----Original Message-----
| >Dwayne:
| >
| >Using Send object, there is no way to specify an object
| name. There are a
| >couple of ways to do it.
| >
| >1.) Use Automation with Outlook to grab the message after
| you create it
| >(search on the subject) and you can then deal with
| attachments.
| >
| >2.) Use method to send the mail, again such as
| programming the Outlook
| >object (see the MS KB), or using another third party
| emailing utility to
| >create the mail in Outlook; there are many third party
| utilities out there,
| >including our PDF and Mail Library for Access.
| >--
| >Steve Arbaugh
| >ACG Soft
| >http://ourworld.compuserve.com/homepages/attac-cg
| >
| message
| >| >> In the code segment below, we create an RTF file from a
| dB query and
| >attach
| >> it to an e-mail. We would like to give the attachment
| a dynamic name
| >(e.g.,
| >> the variable "foobar") but the SendObject action
| doesn't support naming...
| >> unless we are misreading the arguments. How can we
| attach a name to the
| >> object?
| >>
| >> <!--
| >>
| >> Private Sub Combo7_BeforeUpdate(Cancel As Integer)
| >> On Error Resume Next
| >>
| >> foo = Combo7.Value
| >> bar = Combo7.Text
| >> foobar = Trim(bar) & ".doc"
| >>
| >> newSQL = "SELECT Report_Types.report_type,
| Agency_Codes.Agency_Code,
| >> [DHS Reports].Report_Number,
| classification.classification, [DHS
| >> Reports].Subject, [DHS Reports].Reference, [DHS
| >Reports].Source_Descriptor,
| >> [DHS Reports].Summary, [DHS Reports].Detail, [DHS
| Reports].Significance,
| >> [DHS Reports].Actions_FU, [DHS Reports].Miscellaneous,
| [DHS
| >> Reports].Preparer, status.status_text, [DHS
| Reports].Contact, [DHS
| >> Reports].DOI, [DHS Reports].Release, [DHS Reports].
| [Report Loc],
| >> reporting.Reporting INTO temp FROM (((([DHS Reports]
| LEFT JOIN
| >Report_Types
| >> ON [DHS Reports].Report_Type_Key =
| Report_Types.rpt_type_id) LEFT JOIN
| >> Agency_Codes ON [DHS Reports].Agency_Code_Key =
| Agency_Codes.ag_cd_id)
| >LEFT
| >> JOIN classification ON [DHS Reports].Classification =
| >> classification.classID) LEFT JOIN reporting ON [DHS
| Reports].Reporting =
| >> reporting.rptg_id) INNER JOIN status ON [DHS
| Reports].Status =
| >> status.statusID WHERE ((([DHS Reports].ID)=" & Trim(Str
| (foo)) & "));"
| >>
| >> DoCmd.RunSQL newSQL
| >> DoCmd.SendObject acOutputReport, "e-mail",
| acFormatRTF, , , , bar,
| >> foobar, True
| >>
| >> End Sub
| >>
| >>
| >
| >
| >.
| >
|
 
D

Dwayne Conyers

That did the trick! The only "gotcha" is that with the addition of the code
below, the action only works once. We have to close and re-open the form to
get it to fire off a second time. Otherwise, the renaming part works.

d.c.


Alick said:
Hi Dwayne,

As Steve said by using Send object, there is no way to specify an object
name, however, it seems the report attachment file name depends on its
caption property, we can change the report's caption value before we call
sendobject method, this way, the file name can be created dynamically.

The following sample code changes the report's caption dynamically:

DoCmd.OpenReport "aaa", acViewDesign

'aaa is the report name, change its caption to string "hello"
Reports("aaa").Caption = "hello"

'save the changes
DoCmd.Close acReport, "aaa", acSaveYes

'the printed file is hello.rtf
DoCmd.SendObject acSendReport, "aaa", acFormatRTF

If you would like to keep the original caption value, you can keep the
original caption value and change it back after you call sendobject method.

But this method does not change the file extension, the file extension is
controlled by the format, it seems there is no way to change the file
extension before the file is created, after the file is created, there may
be some method to change it, such as the method Steven mentioned - to
access outlook object module (if you don't have Microsoft Outlook, instead
you have Outlook Express, it is much complex to deal with Outlook Express).

Please feel free to reply to the threads if you have any concerns or
questions.



Sincerely,

Alick Ye, MCSD
Product Support Services
Microsoft Corporation
Get Secure! - <www.microsoft.com/security>

This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
| Content-Class: urn:content-classes:message
| From: "Dwayne Conyers" <[email protected]>
| Sender: "Dwayne Conyers" <[email protected]>
| X-Tomcat-NG: microsoft.public.access.reports
|
| Unfortunately, that presents more complexity than the
| client will support. We won't have access to Exchange
| Server and are limited in running macros in that
| environment...
|
| d.c.
|
|
| >-----Original Message-----
| >Dwayne:
| >
| >Using Send object, there is no way to specify an object
| name. There are a
| >couple of ways to do it.
| >
| >1.) Use Automation with Outlook to grab the message after
| you create it
| >(search on the subject) and you can then deal with
| attachments.
| >
| >2.) Use method to send the mail, again such as
| programming the Outlook
| >object (see the MS KB), or using another third party
| emailing utility to
| >create the mail in Outlook; there are many third party
| utilities out there,
| >including our PDF and Mail Library for Access.
| >--
| >Steve Arbaugh
| >ACG Soft
| >http://ourworld.compuserve.com/homepages/attac-cg
| >
| message
| >| >> In the code segment below, we create an RTF file from a
| dB query and
| >attach
| >> it to an e-mail. We would like to give the attachment
| a dynamic name
| >(e.g.,
| >> the variable "foobar") but the SendObject action
| doesn't support naming...
| >> unless we are misreading the arguments. How can we
| attach a name to the
| >> object?
| >>
| >> <!--
| >>
| >> Private Sub Combo7_BeforeUpdate(Cancel As Integer)
| >> On Error Resume Next
| >>
| >> foo = Combo7.Value
| >> bar = Combo7.Text
| >> foobar = Trim(bar) & ".doc"
| >>
| >> newSQL = "SELECT Report_Types.report_type,
| Agency_Codes.Agency_Code,
| >> [DHS Reports].Report_Number,
| classification.classification, [DHS
| >> Reports].Subject, [DHS Reports].Reference, [DHS
| >Reports].Source_Descriptor,
| >> [DHS Reports].Summary, [DHS Reports].Detail, [DHS
| Reports].Significance,
| >> [DHS Reports].Actions_FU, [DHS Reports].Miscellaneous,
| [DHS
| >> Reports].Preparer, status.status_text, [DHS
| Reports].Contact, [DHS
| >> Reports].DOI, [DHS Reports].Release, [DHS Reports].
| [Report Loc],
| >> reporting.Reporting INTO temp FROM (((([DHS Reports]
| LEFT JOIN
| >Report_Types
| >> ON [DHS Reports].Report_Type_Key =
| Report_Types.rpt_type_id) LEFT JOIN
| >> Agency_Codes ON [DHS Reports].Agency_Code_Key =
| Agency_Codes.ag_cd_id)
| >LEFT
| >> JOIN classification ON [DHS Reports].Classification =
| >> classification.classID) LEFT JOIN reporting ON [DHS
| Reports].Reporting =
| >> reporting.rptg_id) INNER JOIN status ON [DHS
| Reports].Status =
| >> status.statusID WHERE ((([DHS Reports].ID)=" & Trim(Str
| (foo)) & "));"
| >>
| >> DoCmd.RunSQL newSQL
| >> DoCmd.SendObject acOutputReport, "e-mail",
| acFormatRTF, , , , bar,
| >> foobar, True
| >>
| >> End Sub
| >>
| >>
| >
| >
| >.
| >
|
 
A

Alick [MSFT]

Hi Dwayne,

Glad the information helps :- )


Sincerely,

Alick Ye, MCSD
Product Support Services
Microsoft Corporation
Get Secure! - <www.microsoft.com/security>

This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
| Reply-To: "Dwayne Conyers" <[email protected]>
| From: "Dwayne Conyers" <[email protected]>
|
| That did the trick! The only "gotcha" is that with the addition of the
code
| below, the action only works once. We have to close and re-open the form
to
| get it to fire off a second time. Otherwise, the renaming part works.
|
| d.c.
|
|
| | > Hi Dwayne,
| >
| > As Steve said by using Send object, there is no way to specify an object
| > name, however, it seems the report attachment file name depends on its
| > caption property, we can change the report's caption value before we
call
| > sendobject method, this way, the file name can be created dynamically.
| >
| > The following sample code changes the report's caption dynamically:
| >
| > DoCmd.OpenReport "aaa", acViewDesign
| >
| > 'aaa is the report name, change its caption to string "hello"
| > Reports("aaa").Caption = "hello"
| >
| > 'save the changes
| > DoCmd.Close acReport, "aaa", acSaveYes
| >
| > 'the printed file is hello.rtf
| > DoCmd.SendObject acSendReport, "aaa", acFormatRTF
| >
| > If you would like to keep the original caption value, you can keep the
| > original caption value and change it back after you call sendobject
| method.
| >
| > But this method does not change the file extension, the file extension
is
| > controlled by the format, it seems there is no way to change the file
| > extension before the file is created, after the file is created, there
may
| > be some method to change it, such as the method Steven mentioned - to
| > access outlook object module (if you don't have Microsoft Outlook,
instead
| > you have Outlook Express, it is much complex to deal with Outlook
| Express).
| >
| > Please feel free to reply to the threads if you have any concerns or
| > questions.
| >
| >
| >
| > Sincerely,
| >
| > Alick Ye, MCSD
| > Product Support Services
| > Microsoft Corporation
| > Get Secure! - <www.microsoft.com/security>
| >
| > This posting is provided "AS IS" with no warranties, and confers no
| rights.
| >
| >
| > --------------------
| > | Content-Class: urn:content-classes:message
| > | From: "Dwayne Conyers" <[email protected]>
| > | Sender: "Dwayne Conyers" <[email protected]>
| > | X-Tomcat-NG: microsoft.public.access.reports
| > |
| > | Unfortunately, that presents more complexity than the
| > | client will support. We won't have access to Exchange
| > | Server and are limited in running macros in that
| > | environment...
| > |
| > | d.c.
| > |
| > |
| > | >-----Original Message-----
| > | >Dwayne:
| > | >
| > | >Using Send object, there is no way to specify an object
| > | name. There are a
| > | >couple of ways to do it.
| > | >
| > | >1.) Use Automation with Outlook to grab the message after
| > | you create it
| > | >(search on the subject) and you can then deal with
| > | attachments.
| > | >
| > | >2.) Use method to send the mail, again such as
| > | programming the Outlook
| > | >object (see the MS KB), or using another third party
| > | emailing utility to
| > | >create the mail in Outlook; there are many third party
| > | utilities out there,
| > | >including our PDF and Mail Library for Access.
| > | >--
| > | >Steve Arbaugh
| > | >ACG Soft
| > | >http://ourworld.compuserve.com/homepages/attac-cg
| > | >
| > | message
| > | >| > | >> In the code segment below, we create an RTF file from a
| > | dB query and
| > | >attach
| > | >> it to an e-mail. We would like to give the attachment
| > | a dynamic name
| > | >(e.g.,
| > | >> the variable "foobar") but the SendObject action
| > | doesn't support naming...
| > | >> unless we are misreading the arguments. How can we
| > | attach a name to the
| > | >> object?
| > | >>
| > | >> <!--
| > | >>
| > | >> Private Sub Combo7_BeforeUpdate(Cancel As Integer)
| > | >> On Error Resume Next
| > | >>
| > | >> foo = Combo7.Value
| > | >> bar = Combo7.Text
| > | >> foobar = Trim(bar) & ".doc"
| > | >>
| > | >> newSQL = "SELECT Report_Types.report_type,
| > | Agency_Codes.Agency_Code,
| > | >> [DHS Reports].Report_Number,
| > | classification.classification, [DHS
| > | >> Reports].Subject, [DHS Reports].Reference, [DHS
| > | >Reports].Source_Descriptor,
| > | >> [DHS Reports].Summary, [DHS Reports].Detail, [DHS
| > | Reports].Significance,
| > | >> [DHS Reports].Actions_FU, [DHS Reports].Miscellaneous,
| > | [DHS
| > | >> Reports].Preparer, status.status_text, [DHS
| > | Reports].Contact, [DHS
| > | >> Reports].DOI, [DHS Reports].Release, [DHS Reports].
| > | [Report Loc],
| > | >> reporting.Reporting INTO temp FROM (((([DHS Reports]
| > | LEFT JOIN
| > | >Report_Types
| > | >> ON [DHS Reports].Report_Type_Key =
| > | Report_Types.rpt_type_id) LEFT JOIN
| > | >> Agency_Codes ON [DHS Reports].Agency_Code_Key =
| > | Agency_Codes.ag_cd_id)
| > | >LEFT
| > | >> JOIN classification ON [DHS Reports].Classification =
| > | >> classification.classID) LEFT JOIN reporting ON [DHS
| > | Reports].Reporting =
| > | >> reporting.rptg_id) INNER JOIN status ON [DHS
| > | Reports].Status =
| > | >> status.statusID WHERE ((([DHS Reports].ID)=" & Trim(Str
| > | (foo)) & "));"
| > | >>
| > | >> DoCmd.RunSQL newSQL
| > | >> DoCmd.SendObject acOutputReport, "e-mail",
| > | acFormatRTF, , , , bar,
| > | >> foobar, True
| > | >>
| > | >> End Sub
| > | >>
| > | >>
| > | >
| > | >
| > | >.
| > | >
| > |
| >
|
|
|
 

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

Similar Threads

A problem with a report... 5
Error 7

Top