Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Button to e-mail selected pages of a report in Snapshot Format

Status
Not open for further replies.

SyBeerianTyGRRRR

Technical User
Jul 16, 2003
31
0
0
GB
Hi folks,

Can anyone tell me how to create a cmd button on a Form that when clicked will send the the report pages of the currently selected record to an e-mail recipient that is selected in a drop down combo box on the same form??

I am trying to use a variation of some code i use to print selected pages of a report. This code is as follws:

Private Sub Command98_Click()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "rptPlmkrsInfSheet"
stLinkCriteria = "[AddressID] = " & Me.AddressID

DoCmd.SendObject stDocName, acNormal, , stLinkCriteria
End Sub

Basically i replaced OpenReport with SendObject but i appear to be missing something somewhere as this returns the following message:

"The format inwhich you are attempting to output the current object is not available"

Report Snapshot format is what i want but i don't know how to invoke this format in VBA??

The names of the relevant components are as follows:

Form from which record is selected = frmPlmkrsDbse
Primary Key of form = AddressID
Underlying Table that contains records = tblPlmkrsDbse
Report name = rptPlmkrsInfSheet (each record produces a 2 page report.)
Combo Box that contains e-mail addresses = cboMailCoach

Any assistance would be much appreciated.

Thanks
 
Perhaps you should try exporting your data to another format and then sending the exported file. Rich Text works well as it retain's all of your report's formatting and opens without any hassles in Word. By exporting to a file you provide a definate object for the email to send as an attachment and for the email recipient to open on the other side.

Here is a sample of how to send one or more files to an email recipient as attachments. strSend to is the recipient's eMail address, and varAttach is an array that holds the names of one or more attachments to look for and send. You could, if you only want to send one report, replace varAttach with a single-string argument for one report and remove the For-Next loop. This would be a good way to handle sending one report at a time after the data is exported.

'///////////////////////////////////////////////////////////////////////////////////////////////////

Sub subSendMail(strSendTo As String, varAttach As Variant)

' Access Outlook's functionality:

Dim objOutlook As Outlook.Application
Set objOutlook = CreateObject("Outlook.Application")

' Create a new e-mail:

Dim objEmail As Outlook.MailItem
Set objEmail = objOutlook.CreateItem(olMailItem)

' Access the windows file system:

Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")

' Add recipient's e-mail address to a new line at the end of the logfile:

log.WriteBlankLines (1)
log.WriteLine (strSendTo)
log.WriteBlankLines (1)

' Set e-mail attributes:

With objEmail

' Put the recipient in the "to" box:

.To = strSendTo

' Begin the subject line:

.Subject = "Reconciliation Reports ("

' No text appears in the message body:

.Body = ""

' Enter a loop to add attachments to the e-mail:

Dim strLine As String

Dim i As Integer
Dim a As Boolean
a = False

For i = 0 To UBound(varAttach)

strLine = " " & varAttach(i) & String(Abs(36 - Len(varAttach(i))), Chr(32))

If fs.FileExists(strSPath & varAttach(i)) = True Then

' Set a to true

a = True

' Add report name to the subject:

.Subject = .Subject & varAttach(i) & ", "

' Add report to the e-mail as an attachment:

.Attachments.Add strSPath & varAttach(i), olByValue

End If

Next i

' Finish the subject line:

.Subject = Left(.Subject, Len(.Subject) - 2) & ")"

' Send the e-mail if it has attachments to send:

If a = True Then .Send

End With

End Sub

'///////////////////////////////////////////////////////////////////////////////////////////////////
 
oh, you might want to remove the log.writeline stuff in there. this was all put in for recording which filed were and weren't located when the recording process occurred, but doesn't work without the file first being set up by some outside procedures. thought i removed it all after i pasted that sample in here, but seem to have missed a few lines.
 
Many thanks for your reply, i'm not yet sure whether what you have suggested is where i want to go but you have given me some ideas that will help anyway.

Once again many thanks indeed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top