Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Emailing in Access 1

Status
Not open for further replies.
Jun 22, 2006
7
GB
What I am trying to do is create a form in access, and send the form to an email address by using a tab button.
So that the form is sent in an email
 
Outlook is pretty easy. Can you give me an example of what kind of data you want to send from the form? Formatting the body of the email is usually the hardest part. I'll put up a sample script in a few minutes.
 
Code:
Private Sub Submit_Click()


Dim appOutlook As Outlook.Application
Dim ItmNewEmail As Outlook.MailItem



DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70 'save record before proceeding

Set appOutlook = New Outlook.Application
Set ItmNewEmail = appOutlook.CreateItem(olMailItem)


With ItmNewEmail
     .To = "add1@domain.com; add2@domain.com"
     .CC = Forms("FormName").Controls("RequestorEmail").Value
     .Subject = "Subject"
     .Body = "A new email has been sent by" & Forms("FormName").Controls("ControlName").Value & " for Job Number " & Forms("FormName").Controls("ControlName").Value & Chr(13) & "sample text" & Forms("FormName").Controls("ControlName").Value & Chr(13) & Chr(13) & Forms("FormName").Controls("ControlName") & Chr(13) & "More Sample Text " & Forms("FormName").Controls("ControlName") & Chr(13) & Chr(13) & Forms("FormName").Controls("ControlName")
     

     .Send                    ' send files and notification
End With

End Sub

As you can see, there is a lot of information from the form included in a hard coded paragraph. You can always make the email contain purely info from the form, just make sure to put spaces where you want them, etc...

Hope this helps,

Alex
 
Many Thanks in advance ....and for previous help.

What I am wanting to do is ...

Create a form / database which can be accessed by employees

Have holiday requests and shift swaps entered into the database

Then for this information to be forwarded on to the relevant person by email.


So that the email contains the form that had been completed.
 
I am not sure if you can take a screen shot and send it in the email, or anything along those lines. I think you have a couple of choices though:

1. You can hard-code a message in the body of the email and add values from form controls where you want them (as I did in example)
2. You could design a report, print it to a .pdf and attach it to the email.

I obviously prefer taking a hard coded message and inserting values from form controls where needed, but I might be able to modify some other code I have to attach your .pdf. Basically what you'll want to do is have a "submit" button on your form, and when you click first have it print the report to a set directory and then attach from said directory into your email as layed out in the second part of your sub. I believe under subject you would put ".Attach" or ".Attachment" = file directory\filename. I think it's .Attach but not 100% sure off hand.

Hope this Helps,

Alex
 
What would the coding be to enable me to do this ??
Is there a possibility that you could explain in a little more detail on what I am supposed to do, as I am not that experienced in access, I did get so far as being able to send an email from the form... the rest of it has got me all puzzled. Many Thanks
 
It would be something like this:
Code:
.Body = "Type some sample text here, make sure that it is in quotes " & Forms("Some Form).Controls("Some Control").Value & " Make sure you include spaces at beginning and end of text strings where appropriate or else you will see twowordsrightnext to each other in the email " & Chr(13) & " Chr(13) serves to skip a line " & Forms("Some Form").Controls("Some Control").Value

So I'm not sure how your setup is going to work but you could try something like this:

Code:
.Body = Forms("MyForm").Controls("EmployeeName").Value & " has requested a " & Forms("MyForm").Controls("ShiftSwapOrHoliday").Value & " on " Forms("MyForm").Controls("RequestedDate").Value & "." & Chr(13) & Chr(13) & "This request was made on " & Forms("MyForm").Controls("SubmissionDate") & " at " & Forms("MyForm").Controls("SubmissionTime")

Or something along those lines. Told ya formatting the body was the tricky part ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top