Add attachment to email from search result link (1 Viewer)

DatabaseTash

Registered User.
Local time
Today, 22:33
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:33
Joined
May 7, 2009
Messages
19,175
change this:

...
....
.Attachments.Add Me![yourSubformName].Form![Plan Link]
 

DatabaseTash

Registered User.
Local time
Today, 22:33
Joined
Jul 23, 2018
Messages
149
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:33
Joined
May 7, 2009
Messages
19,175
you investigate, in desing view, what is the Name of the textbox "Plan link"
 

DatabaseTash

Registered User.
Local time
Today, 22:33
Joined
Jul 23, 2018
Messages
149
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:33
Joined
May 7, 2009
Messages
19,175
i look like the field is Hyperlink:

.Attachments.Add Split(Me![frmSubCombinedParishSearch].Form![Plan link], "#")(1)
 

DatabaseTash

Registered User.
Local time
Today, 22:33
Joined
Jul 23, 2018
Messages
149
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"
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:33
Joined
May 7, 2009
Messages
19,175
you can use another method:

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

Users who are viewing this thread

Top Bottom