Add attachment to email from search result link

DatabaseTash

Registered User.
Local time
Tomorrow, 04:05
Joined
Jul 23, 2018
Messages
149
I would like to add the option of emailing a plan as an attachment, once the user has searched for the plan.
I have managed to work out the code to get the email to pop up (very chuffed about that! :D).
I would now like to get the code to use the search result (See screen shot for example). So it would use the Plan Number in the subject line and use the Plan Link to attach the file to the email. The attachment files are .pdf or .tif files.

I would like the user to be able to click the button, rather than have to perform an additional search. Is this the best way to do this or is there an easier way? I would be grateful for any suggestions!
Inkedsearchexample_LI.jpg



Code:
Option Compare Database


Private Sub Command19_Click()

Dim Msg As String

Msg = "This plan has been sent to you with the help of Survey Central."

Dim O As Outlook.Application
Dim M As Outlook.MailItem

Set O = New Outlook.Application
Set M = O.CreateItem(olMailItem)



With M
    .BodyFormat = olFormatHTML
    .Subject = "Plan Number " & [Plan Number] & ""
    .Display
    .HTMLBody = Msg & .HTMLBody
    .Attachments.Add "R:\Digital Library\"
    
    
    
End With
  
Set M = Nothing
Set O = Nothing


End Sub
 
change this:

...
....
.Attachments.Add Me![yourSubformName].Form![Plan Link]
 
change this:

...
....
.Attachments.Add Me![yourSubformName].Form![Plan Link]
Thanks for the reply!

I just tried it.
I seem to be getting a Run-time error '438' Object doesn't support the property or method. When I Debug it highlights the .attachments. Add line.

This is what I changed the code to:
Code:
Option Compare Database


Private Sub Command19_Click()

Dim Msg As String

Msg = "This plan has been sent to you with the help of Survey Central."

Dim O As Outlook.Application
Dim M As Outlook.MailItem

Set O = New Outlook.Application
Set M = O.CreateItem(olMailItem)



With M
    .BodyFormat = olFormatHTML
    .Subject = "Plan Number " & Me![frmSubCombinedParishSearch].Form![Plan Number] & ""
    .Display
    .HTMLBody = Msg & .HTMLBody
    .Attachments.Add Me![frmSubCombinedParishSearch].Form![Plan link]
    
    
    
End With
  
Set M = Nothing
Set O = Nothing


End Sub
 
you investigate, in desing view, what is the Name of the textbox "Plan link"
 
It appears to be "Plan link"
Is the the square brackets the correct thing to put around it seeing there is a space??

CapturePlanLink.JPG
 
i look like the field is Hyperlink:

.Attachments.Add Split(Me![frmSubCombinedParishSearch].Form![Plan link], "#")(1)
 
i look like the field is Hyperlink:

.Attachments.Add Split(Me![frmSubCombinedParishSearch].Form![Plan link], "#")(1)
Yes, that is a hyperlink field.
I just tried that and got the error "run-time error '9': Subscript out of range"
 
you can use another method:

.Attachments.Add HyperlinkPart(Me![frmSubCombinedParishSearch].Form![Plan link], acFullAddress)
 

Users who are viewing this thread

Back
Top Bottom