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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Coding a button on a form in Access

Status
Not open for further replies.

ogriv

Programmer
Jun 6, 2013
7
US
I just read a thread where a user name tbl offered the following code. What I need is to code a button on a form in Access such that when the button is clicked, the form will be emailed to 2 recipients via Lotus Notes. Will this code do that for me? Thanks!


'Public Sub SendNotesMail(Subject as string, attachment as string,
'recipient as string, bodytext as string,saveit as Boolean)
'This public sub will send a mail and attachment if neccessary to the
'recipient including the body text.
'Requires that notes client is installed on the system.

'Public Sub SendNotesMail(Subject As String, Attachment As String, Recipient As String, BodyText As String, SaveIt As Boolean)
Public Sub SendNotesMail(SavePathExcel, Title, FileType, Addressee)
'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")
'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
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
Else
Maildb.OPENMAIL
End If
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
'MailDoc.sendto = Recipient
MailDoc.sendto = Addressee '"Richard"
'MailDoc.Subject = Subject
MailDoc.Subject = Title
'MailDoc.Body = BodyText
MailDoc.Body = "User Text............"
'MailDoc.SAVEMESSAGEONSEND = SaveIt
MailDoc.SAVEMESSAGEONSEND = False

'Set up the embedded object and attachment and attach it
Attachment = SavePathExcel & Title & FileType
If Attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
MailDoc.CREATERICHTEXTITEM ("Attachment")
End If
'Send the document
MailDoc.SEND 0, Recipient
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub
 
Well I can easily add in a line to cc someone else.. but what I am actually curious about is whether or not it will send the actual form that the button is located on through lotus notes just by clicking it.
 
No, it's written to attach an Excel file.

The building blocks are (mostly) all there. You just need to work out how to turn your "form" into something attachable.
 
Is there a way to do it without having to turn my form into something attachable or is that the only option?
 
I imagine that you could transcribe the information on the form into the body of the email.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top