473,414 Members | 1,643 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Open outlook in access with body auto fill from form

8
Hey I am so close from finishing this database I just need one more issue solve thanks. Basically I have a code within a form that opens up outlook and fill in the body of the email, among other informations, with event infos, but I need it to also fill in the Venue. The problems is the venue exist in the form as a subform, and I don't know how to reference it in the code. Here is the code I hope you can help, I ran into so much problems trying to finish this database, mostly technical, and my teacher never used outlook object so he couldn't help. But at this point I just want to get this done. Thanks for your help, I basically want the reference at the .Body area.

Private Sub Command31_Click()
On Error GoTo Err_SendEmail

Dim objOutlook As New Outlook.Application
Dim objMail As Outlook.MailItem
Dim sSQL As String, db As DAO.Database, rs As DAO.Recordset
Dim sTitle As String, sFile As String, sErr As String

'Prelims
DoCmd.SetWarnings False
DoCmd.Hourglass True
Set db = CurrentDb

'Prepare email message
Set objMail = objOutlook.CreateItem(olMailItem)
With objMail

'Build recordset on recipients
sSQL = "SELECT [EMAIL_ADDRESS] FROM MEMBER_CONTACT;"
Set rs = db.OpenRecordset(sSQL)

'Add Recipient
While Not rs.EOF

With .recipients.Add(rs![EMAIL_ADDRESS])
.Type = olTo
End With

rs.MoveNext
Wend
rs.Close
Set rs = Nothing

'Add the subject
.Subject = "Multi-Asian Club Event: " & Me![EVENT_NAME]

'Add standard message text to body
.Body = .Body & "Event Name: " & Me![EVENT_NAME] & vbCrLf
.Body = "Description: " & Me![EVENT_DESCRIPTION] & vbCrLf
.Body = .Body & "Event Date: " & Me![EVENT_DATE] & vbCrLf
.Body = .Body & "Start Time: " & Me![START_TIME] & vbCrLf
.Body = .Body & "End Time: " & Me![END_TIME] & vbCrLf

'Closure
.Body = .Body & vbCrLf & "Regards" & vbCrLf & vbCrLf & "Your Club"

.Display

End With

'Send the mail message
Set objMail = Nothing
Set objOutlook = Nothing

Exit_SendEmail:
DoCmd.SetWarnings True
DoCmd.Hourglass False
Exit Sub

Err_SendEmail:
sErr = "Error " & Error & " / " & Err
MsgBox sErr, vbInformation + vbOKOnly, "Error on Email subroutine"
Resume Exit_SendEmail


End Sub
Mar 30 '08 #1
6 3649
Stewart Ross
2,545 Expert Mod 2GB
Hi. You should find the answer you need in the following HowTo article linked here: Referring to Items on a Subform. I would show you the exact syntax, but you haven't told us the name of the subform or the name of the field storing the venue. As long as the subform is on the same form as the code you are using it will be along the lines of

Expand|Select|Wrap|Line Numbers
  1. <someexpression> = Me.[subform name].Form![venue control name]
-Stewart
Mar 30 '08 #2
LeoK
8
Hey Thankyou very much, I have been pulling my hair out because of this. by the way the SUBFRM_VENUE and the field name is VENUE_ADDRESS. I did manage to get the venue to show up in the email, but it only show the first venue, so if an event has more then one venue only the first one shown up.
Mar 30 '08 #3
Stewart Ross
2,545 Expert Mod 2GB
Hi. Glad you got this working. When you refer to a subform control value you are referring to the currently-active record, not all records, hence the transfer of just one venue address. If you want to transfer all venue addresses you really need to take a different approach. You could use a loop in code to process a copy of the subform's recordset, which is normally already filtered by the parent-child field link to the main form.

A skeleton for the code for this is shown below:

Expand|Select|Wrap|Line Numbers
  1. Dim rstVenues as DAO.recordset
  2. Dim VenuAddresses as String
  3. Dim Addresscount as Integer
  4.  
  5. Set rstVenues as Me![SUBFRM_VENUE].Form.Recordsetclone
  6. Do while not rstVenues.EOF
  7. Addresscount = Addresscount + 1
  8. If Addresscount = 1 then
  9. VenuAddresses = rstVenues![Venu_Address]
  10. Else
  11. VenuAddresses = VenuAddresses & "; " & rstVenues![Venu_Address]
  12. End If
  13. rstVenues.Movenext
  14. Loop
  15. rstVenues.Close
You may need to add a reference to the MS DAO 3.x object library (if compiler does not recognise the DAO.Recordset statement) - from VB editor choose Tools, References and tick the highest-numbered MS DAO object library.

-Stewart
Mar 30 '08 #4
LeoK
8
Thanks for the reply, but I am getting a compile error "type mismatch" that highlights the .RecordSource, any idea, thanks
Mar 30 '08 #5
LeoK
8
Hey just want to thank you Stewart, I thought it through and it seems that the club will rarely have an event with more then one venue, so I decided not to add complication. Our teacher said in the beginning that we should stay away from project that requires emailing, and that we were not expected to use any VBA, but I decided to just learn VBA and use it. I think it has been successful and a bit fun, and people like you has helped me a lot so thanks.
Mar 31 '08 #6
Stewart Ross
2,545 Expert Mod 2GB
Hey just want to thank you Stewart, I thought it through and it seems that the club will rarely have an event with more then one venue, so I decided not to add complication. Our teacher said in the beginning that we should stay away from project that requires emailing, and that we were not expected to use any VBA, but I decided to just learn VBA and use it. I think it has been successful and a bit fun, and people like you has helped me a lot so thanks.
Sorry Leo - I put Recordsource instead of Recordsetclone - can't imagine what I was thinking at the time. Anyway, I think it is wise of you to avoid unnecessary complications in the circumstances. Well done for taking the simpler approach.

Good luck with future projects.

Regards

Stewart
Mar 31 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: MaxH | last post by:
I need to perform programmatically from a C# .net application the following tasks: _ open an outlook (or default e-mail client) compose message window; _ attach a document to the new message; _...
1
by: joshua | last post by:
Is there a way to set the FROM name (the name the recepient sees as the one who sent the email) when using Access to create an Outlook email message? (Using MS-Office 2000 SP3) We set up an...
0
by: TheCoder | last post by:
I am making a D-base with web conectivity for my class project. I have everything working but the subit button sends the data to the correct fields but afterwards it wants to reproduce new blank...
2
by: Jesper | last post by:
Hi, I wood like to be able to setup an email using outlook (or other email program) from C#, setting up the subject field and write some start text in the message body. Normally I would use...
2
by: Raymond Du | last post by:
Hi, I have a ASP.Net button in a webform. What I like to do, if this button is clicked, the page should connect to a SQL server run some stored procedure, then bring up user's MS Outlook client...
1
by: Mr T | last post by:
I know how to send email from Access and I know how to create a custom form in Outlook. but.... How do I put the email info from Access into the Outlook custom form ??? Dim MyDB As Database Dim...
3
by: Jeff | last post by:
I am trying to send emails from my application (not using a plugin, that will come later), I can create an email and add attachments. I can fill in the body etc. Word works for the editor. So...
23
by: andyoye | last post by:
How can I launch Outlook on users machines when they click a button on a web form (InfoPath)? Thanks
1
by: andyoye | last post by:
Below code is attached with a button on my infopath form. It does work ( auto populates "To:" and "Subject" based on form nodes) but how can I attach the file to the message which is attached to...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.