Thread: Send E mail to a Form field??
11-25-09, 11:23 #1Registered User
- Join Date
- Nov 2009
Unanswered: Send E mail to a Form field??
I am sending an e mail using the following code and its all working oh so well apart from when I put me.email in the send to section I have highlighted I get a debug. I have tested it with my address and its all fine but not when picking up the field any ideas?
Private Sub Form_Close()
Dim Subject As String
Dim Attachment As String
Dim Recipient As String
Dim BodyText As String
Dim SaveIt As Boolean
'Set up the objects required for Automation into lotus notes
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
'Next line only works with 5.x and above. Replace password with your password
'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string or using above password you can use other mailboxes.
UserName = Session.UserName
MailDbName = left$(UserName, 1) & right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.IsOpen = True Then
'Already open for mail
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = Me.Email
MailDoc.Subject = "Archive Booking Confirmation"
MailDoc.Body = "This is to confirm that you booked out archive."
MailDoc.SAVEMESSAGEONSEND = True 'Gets the mail to appear in the sent items folder
'Set up the embedded object and attachment and attach it
If Attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", "", "")
'Send the document
MailDoc.PostedDate = Now()
MailDoc.SEND 0, Recipient
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
11-27-09, 03:42 #2Moderator
- Join Date
- Dec 2004
- Madison, WI
Email is a reserved word and shouldn't be used as a field or variable.
I'd also use me!Email or in your case me![Email]. (notice the ! versus the .) A ! represents the value of the field while a . typically represents the field itself (although new versions of MSAccess are flexible on this 'to a point'.)
But ideally, I'd use something other than just email (ie. vEmail).
If you need other help, there's a few nice emailing examples in the code bank for you to look at. - the code is much easier (and I think you could just use the docmd.sendobject....)
Last edited by pkstormy; 11-27-09 at 03:47.Expert Database Programming
MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)