Send PDF

kitty77

Registered User.
Local time
Today, 13:35
Joined
May 27, 2019
Messages
719
I'm using the falling code...

Private Sub Command93_Click()
Dim strDocName As String
Dim strWhere As String
strWhere = [Mrecordid] = " & Me!Mrecordid"
DoCmd.SendObject acSendReport, strDocName, acFormatPDF, strWhere
End Sub

It is a button on a report. It sends the report as an attachment but its sending it as the report name. I would like it to send as the [Mrecordid]

What am I doing wrong? Also, can't seem to get To, Subject, etc... to show.

Thanks...
 
Hi. Here's a reference to the SendObject Method. You seem to be mixing it with the OpenReport method. The SendObject method doesn't have a WhereCondition argument.
 
I tried this...

DoCmd.SendObject acSendTable, "Employees", acFormatXLS, _
"Nancy Davolio; Andrew Fuller", "Joan Weber", , _
"Current Spreadsheet of Employees", , False

And modified it to this...

DoCmd.SendObject acSendReport, "BRODS", acFormatPDF, _
"bob@abc123.com", "Joan Weber", , _
"Current Spreadsheet of Employees", , False

I get an error... Unknown message recipient(s); the message was not sent
 
Well I believe you have to have those names in your contacts address book if you use actual names.
Do you actually have a Joan Weber ?
 
So either send to an actual email address or a name in your list.
Bob@abc123.com is also likely to bounce. :)
 
Ok, I got the following to work...

DoCmd.SendObject acSendReport, "BRODS", acFormatPDF, , , , "Subject", "Body", False

How can I change the "BRODS" to be a value in a field called [Mrecordid]?

Thanks!
 
Have you tried just substituting the control name?

Is Mrecordid a string?
 
Ok, I got the following to work...

DoCmd.SendObject acSendReport, "BRODS", acFormatPDF, , , , "Subject", "Body", False

How can I change the "BRODS" to be a value in a field called [Mrecordid]?

Thanks!
Hi Kitty. Is "BRODS" the name of a report? If so, are you storing the name of the report to email in the Mrecordid field?
 
So, it starts on a form with a command button. Click the button and it opens up a report called "BRODS" based on the [Mrecordid]

The report has a command button that will then send it to email. Right now, it working but the email attachment is called "BRODS" and want it to be [Mrecordid]
 
So, it starts on a form with a command button. Click the button and it opens up a report called "BRODS" based on the [Mrecordid]

The report has a command button that will then send it to email. Right now, it working but the email attachment is called "BRODS" and want it to be [Mrecordid]
Okay, if the button to send out the email is on the report, then try adding the following code just before the SendObject line:
Code:
Me.Caption = Me.Mrecordid
Hope it helps...
 
on the click of your button:
Code:
private sub button_click()
dim sReport As string
sReport= [MrecrodID] & ""
on error resume next
docmd.deleteobject acReport, sReport
docmd.copyobject , sReport, acReport, "BRODS"
docmd.openreport sReport, acViewPreview, , , acHidden
DoCmd.SendObject acSendReport, sReport, acFormatPDF, , , , "Subject", "Body", False
docmd.deleteobject acReport, sReport
end sub
 
One more thing... Using that same code, how can I select a specific Outlook account to send the email? Right now, it sends through the default account.
 
One more thing... Using that same code, how can I select a specific Outlook account to send the email? Right now, it sends through the default account.
Hi. SendObject simply uses all the default settings on your computer (email client and account). If you're using Outlook and want to send the email out using a specific account, then you'll have to use Outlook Automation.
 
One more thing... Using that same code, how can I select a specific Outlook account to send the email? Right now, it sends through the default account.

This code is from my Outlook, but you should be able to adapt.

Code:
Public Function ListEMailAccounts(AcctToUSe As String) As Integer
    Dim outApp As Object
    Dim i As Integer
    Dim AccNo As Integer
    Dim emailToSendTo As String
    
    Set outApp = CreateObject("Outlook.Application")
   
    AccNo = 1
    'if smtp address=email we want to send to, acc no we are looking for is identified
    For i = 1 To outApp.Session.Accounts.Count
        'Uncomment the Debug.Print command to see all email addresses that belongs to you
'Debug.Print "Acc name: " & OutApp.Session.Accounts.Item(i) & " Acc number: " & i & " , email: " & OutApp.Session.Accounts.Item(i).SmtpAddress
        'If OutApp.Session.Accounts.Item(i).SmtpAddress = emailToSendTo Then
        If outApp.Session.Accounts.Item(i).DisplayName = AcctToUSe Then

            AccNo = i
            Exit For
        End If
    Next i
    ListEMailAccounts = AccNo
    Set outApp = Nothing
End Function

and I call it like below

Code:
    strAccount = "Account Name"
    
    intAccount = ListEMailAccounts(strAccount)
    '
    'Now create email
    Set olMail = Application.CreateItem(olMailItem)
    olMail.To = "Bob@abc123.com"
    olMail.Subject = "Unread emails from home PC"
    olMail.SendUsingAccount = Application.Session.Accounts.Item(intAccount)

Instead of Application. you would use the name of the object you created for Outlook. outApp perhaps.?

Search the site on how to attach a file(s), but it would be something like in the link below

https://docs.microsoft.com/en-us/office/vba/api/outlook.attachments.add

HTH
 

Users who are viewing this thread

Back
Top Bottom