command button to email form

R

Ruth

Hi there

I am trying to email a form with a command button that uses Outlook to
email. I am using the following code:

Private Sub btnEMAIL1_Click()
Dim mess_body As String
Dim rst As DAO.Recordset
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
Set rst = Form_F_People_Mailings.RecordsetClone
rst.MoveFirst
Do While Not rst.EOF
If IsNull(rst!Email) Then
MsgBox "skipping " & _
Form_F_People_Mailings.LastName & _
" no email address."
GoTo skip_email
End If
mess_body = "Dear " & rst!Salutation & " " & _
rst!LastName & "," & _
vbCrLf & vbCrLf & Me.Mess_Text
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
With MailOutLook
..To = rst!Email
..Subject = Me.Mess_Subject
..Body = mess_body
If Left(Me.Mail_Attachment_Path, 1) <> "<" Then
..Attachments.Add (Me.Mail_Attachment_Path)
End If

Exit_btnEMAIL1_Click:

End Sub



I get an error that states "Compiled Error User defined type not defined"

and it highlights the line stating :
"appOutLook As Outlook Application"

How is this fixed?
 
M

mscertified

In a code window, click Tools--references and select the Outlook object
library.

-Dorian
 
R

Ruth

Thank-you Dorian

I no longer get that error.... but I get one for a line further down now....

The error message is similar "Compiled error Method or data member not
found" and the part highlighted is:

"rst!LastName"

amoungst the lines:
mess_body = "Dear " & rst!Salutation & " " & _
rst!LastName & "," & _
vbCrLf & vbCrLf & Me.Mess_Text


BUT I don't want it to do that anyway. If possible I want the form to go
into the body of the email instead. Is there a way to change the code so the
form is in the body rather than the salutation?
 
M

mscertified

either rst is undeclared or Lastname is not a column in the table.

You can't put a form in an email.
A from is an Acceess object not an Outlook object.
You have to transfer each field on the form to the email individually.

-Dorian
 
R

Ruth

Maybe I am stretching it, but is there a way to put a report with the current
record number which is unique in the body of an email? If so, what is the
code to do this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top