FilePath is name of textbox on frmContacts in OP's database I downloaded from post1. Code is behind that form.
Unfortunately, I did not test code. Just tried and Outlook does open but is not attaching file. Which is odd because this should work. Here is code in my db that does work:
Code:
Private Sub EmailWithSig()
Dim oApp As Object, OMail As Object, signature As String
Set oApp = CreateObject("Outlook.application")
Set OMail = oApp.CreateItem(0)
With OMail
.To = "email address here"
.Subject = "Subject"
.Attachments.Add "C:\AlaskaLTC.pdf"
.Display 'email must be displayed for the next line to work
.HTMLBody = "Message." & vbNewLine & .HTMLBody
'.Send
End With
Set OMail = Nothing
Set oApp = Nothing
End Sub
I just tried hard-coding of a filepath in the code and it works. So there is something about referencing the textbox. Stepping through code, I see the value of textbox is the filepath but for some reason Attachments.Add is not acknowledging it. So I created a string variable and set it with value of textbox. This code works:
PMFJI - This is a common gotcha with Outlook Automation.
Using Me.SomeControl within a With OLObject... construct seems to always give issues, so creating variables to hold all the elements you need for the mail object is a really good practice to get into.
As an added benefit it also makes for easier debugging as well.
Gasmn i use the vba editor ...
You mean the problem is because i put Variable and must be Variant? Please....if you want modify the code in order to solve the issue..(i will appreciate a lot)
Change the word Variable to String
Then please compile using Debug/Compile on the menu. This will highlight any other issues.
Computers are stupid, you and I might know that Variable is meant to be Variant, but a computer would not.
You should also have
Code:
Option Compare Database
Option Explicit
or at least the Explicit statement at the top of each module/form
This will then allow you to find spelling mistakes and the like.
I do appreciate that you are a learner at this, as I was (and still am, as it is a continuous process), but you have to start learning how to code, if you want to do complex tasks like this.
You will find code on the net and here that will do a lot of what you want, but you will need to tailor it on nearly every occasion.