PDA

View Full Version : Solved: Email contents of Form as txt INSIDE email ?



bdsii
01-26-2011, 01:02 PM
I am new to Access and VBA and am hoping someone here can help. I would like to accomplish the following using Access commands or through VBA:

When a new record is added via a form, the user would click on a command button and the contents of the form for the new record would be emailed to a predetermined listing of recipients with the data from the form being included inside the body of the email as TXT and not as an attachment.
The data that is being sent should be only for the new record and not the records for the entire table.I can send the form contents as several different types of attachments using the SendObject command inside a macro but have not found a way to simply paste the data inside an Outlook email rather than using an attachment.

Basically, I would like the same results as if the user had submitted the data in an HTML document with the MAILTO command and enclosure type as plain text.

I am zipping and attaching a sample db in case it helps. It has one table, one form and one macro that sends the info from the form as an attachment. I am hoping to replace the attachment with text directly in the email for the newly added record. I have not figured out how to even use the attachment to send out only the newly added record.

I am hoping that VBA may allow this to be solved. Any ideas ?

Thanks in advance for any help or advice.

geekgirlau
01-27-2011, 05:09 PM
You can't use a macro for this, you need VBA


Private Sub EmailForm_Click()
Dim objApp As Object
Dim objMsg As Object
Dim strMsg As String


strMsg = "Construct a string of text from values in your form" & Chr(13) & Chr(13) & _
"ID: " & Me.ID & Chr(13) & _
"Text Field: " & Me.TextField

Set objApp = CreateObject("Outlook.Application")
Set objMsg = objApp.CreateItem(0)

With objMsg
.To = "email@email.com"
.Subject = "Subject"
.Body = strMsg
.Display
'.Send
End With

Set objMsg = Nothing
Set objApp = Nothing
End Sub

bdsii
02-01-2011, 06:11 AM
Thanks so much, works great !! - Now I need to be able to run this code to insert the text inside the email as well as attach the current record as a pdf in the same email. Would I do it that combining this VBA with the SendObject macro command ?

Can I run the SendObject macro and for the second step in the macro trigger this VBA code ? I have tried that but cannot get it to run the VBA and I think it is because the VBA code does not produce an output such as a "function routine" or something like that ???

Almost there.....just need to tie up the loose ends. Can you help with that ? :-)

THANKS !!!

geekgirlau
02-01-2011, 12:03 PM
You can't use with SendObject as this will send 2 emails. This is untested, but if necessary you can check the correct syntax by searching for attachments in Outlook.


With objMsg
.To = "email@email.com"
.Subject = "Subject"
.Body = strMsg
.Attachment.Add = "Path of attachment"
.Display
'.Send
End With

geekgirlau
02-01-2011, 08:20 PM
Ok, slight adjustment:







With objMsg
.To = "email@email.com"
.Subject = "Subject"
.Body = strMsg
.Attachments.Add = "Path of attachment"
.Display
'.Send
End With

bdsii
02-03-2011, 08:21 PM
thanks !! I really appreciate it :-)