Email to selected list option

Sorry yes I had already changed the header I just copied old code back here

error is:
Object doesnt support this property or method.

then code in yellow:

.Attachment.Add AttachmentFile
 
change this:

Public Function CreateEmailWithOutlook( _
MessageTo As String, _
MessageCC As String, _
Subject As String, _
MessageBody As String, _
AttachmentFile As String)

to:

Public Function CreateEmailWithOutlook( _
MessageTo As String, _
MessageCC As String, _
Subject As String, _
MessageBody As String, _
AttachmentFile As Variant)
 
Morning
Changes made but still same error:

.Attachment.Add AttachmentFile

Thanks
 
When I hit the Cmd button it is trying to run, the report preview pops up on screen then error appears
 
is it possible for you to upload your db?
 
Hi

I have uploaded a copy of the database due to protection of data it holds I have simply recreated only the relevant forms tables etc


Thanks
 

Attachments

Hi

Uploaded a second copy of db as may find first copy forms record source was incorrect.

I have created a test record on the form frmJobSheet

hope that helps

thanks
 

Attachments

it was a mistake on my part on this line:
.Attachment.Add AttachmentFile

should be:
.Attachments.Add AttachmentFile
 

Attachments

Thanks excellent work thats now emailing.

Only issue is when it sends it displays a generic report that stays on screen ideally Id rather not see that at all.

Couple of other bits of advice. Now that sends using Outlook automated email can I somehow request a readers reciept so I know the email has been read.

Could I somehow place a msg box when that command button is clicked warning the user that a live job sheet is going to be emailed and press ok to continue or cancel to exit or does that have to be some kind of seperate on click event first?

Thank you so much for your support over last two days its been brillant.
 
Thanks Minty

Would this be the correct place for the code?

In the module?

Thanks

Code:
Public Function CreateEmailWithOutlook( _
                                            MessageTo As String, _
                                            MessageCC As String, _
                                            Subject As String, _
                                            MessageBody As String, _
                                            AttachmentFile As Variant)


    ' Define app variable and get Outlook using the "New" keyword
    Dim olApp As New Outlook.Application
    Dim olMailItm As Outlook.MailItem  ' An Outlook Mail item
    Dim olFolder As Outlook.Folder
    Dim olNameSpace As Outlook.NameSpace
 

    Set olApp = New Outlook.Application
    Set olNameSpace = olApp.GetNamespace("MAPI")
    Set olFolder = olNameSpace.GetDefaultFolder(olFolderInbox)
    ' Create a new email object
    Set olMailItm = olFolder.Items.Add(olMailItem)

    ' Add the To/Subject/Body to the message and display the message
    With olMailItm
        .To = MessageTo
        .CC = MessageCC
        .Subject = Subject
        .Body = MessageBody
        [COLOR="Red"].ReadReceiptRequested = True[/COLOR]
        .Attachments.Add AttachmentFile
        .Display    ' To show the email message to the user
         .Send
         
    End With

    ' Release all object variables
    Set olMailItm = Nothing
    Set olFolder = Nothing
    Set olNameSpace = Nothing
    Set olApp = Nothing

End Function
 
Yes - spot on!
If you have a Google for Outlook Automation there are dozens of attributes that can be set if required.
 
Thanks

I have now sorted the message box and read receipt.

I am still trying to figure out how to stop my db from displaying the report in the previous code before it sends it.

I have commented out the .display code but it still previews the report and leaves it on screen whilst the report is attached and sent correctly via outlook in the back ground.

Any advice?

Thanks
 
Here is the Cmd code:


Code:
Private Sub Command181_Click()


If MsgBox("Warning! You are about to send a LIVE JOB SHEET to a Contractor. Do you wish to continue?", vbYesNo) = vbYes Then



'click the Yes


Dim strDocName As String
Dim strPath As String

strDocName = "Report"
' save report to myDocument
strPath = SpecialFolderPath("MyDocuments") & "\"

If Dir(strPath & strDocName & ".pdf") <> "" Then Kill (strPath & strDocName & ".pdf")

' open report in print preview
DoCmd.OpenReport ReportName:=strDocName, View:=acViewPreview, WhereCondition:="[ID]=" & Me.ID
' create pdf file in mydocuments
DoCmd.OutputTo acOutputReport, strDocName, acFormatPDF, _
strPath & strDocName & ".pdf", True
'close the report
DoCmd.Close acReport, strDocName

' email this report
CreateEmailWithOutlook Me.txtone.Value & "", "info@conquerltd.com", "New Job Sheet", "Dear Trade, New Job Sheet Attached.", _
strPath & strDocName & ".pdf"
Else
'click the no
End If


End Sub
 
I'm not sure using the technique you have that you can suppress it.
You are opening it first with your criteria to restrict the report to the one you are interested in.
If you output the report directly to pdf you won't see it, It might be worth you looking at using openargs to pass the criteria to your report.
 

Users who are viewing this thread

Back
Top Bottom