PDA

Vollständige Version anzeigen : Bericht als Mail


Hoffi
23.03.2004, 19:05
Hallo zusammen,
habe eine kleine Datenbank programmiert, die via code einen bericht in ein Mail Programm übergibt. Das Mail Programm ist Lotus Notes. Leider kann man nur einmal einen bericht übergeben, bei einem 2. Versuch passiert nichts. Erst wenn die Datenbank geschlossen wird und der versuch erneut unternommen wird, funktionierts.
Der Code den ich verwende:

DoCmd.SendObject acReport, stDocName, acFormatRTF, ......

vorab besten Dank für die Hilfe

Nouba
23.03.2004, 19:45
Hier ist ein Modul (nicht von mir), mit dem ich Mails mit Notes auf der Arbeit versende.
'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)
'If you want to send a message to more than one person or copy or blind carbon
'copy the following may be of use to you.
' MailDoc.sendto = Recipient
' MailDoc.CopyTo = ccRecipient
' MailDoc.BlindCopyTo = bccRecipient
'
'Also for multiple email addresses you just set MailDoc.sendto to an array of
' variants each of which will receive the message. So
' Dim recip(25) As Variant
' recip(0) = "emailaddress1"
' recip(1) = "emailaddress2" e.t.c
'
' MailDoc.sendto = recip


'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
Session.Initialize ("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
Else
Maildb.OPENMAIL
End If

'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = Recipient
MailDoc.Subject = Subject
MailDoc.Body = BodyText
MailDoc.SAVEMESSAGEONSEND = SaveIt

'Set up the embedded object and attachment and attach it
If Attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
MailDoc.CREATERICHTEXTITEM ("Attachment")
End If

'Send the document
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
MailDoc.SEND 0, Recipient

'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub

'Public Sub SendNotesAppointment(Username as string, Subject as string, attachment as string,
'recipient as string, Body as string, AppDate as Date, Duration as integer)
'This public sub will write an appointment to a persons diary
'Please specify person as first name lastname
'also change the servername to reflect the notes server name
Public Sub SendNotesAppointment(USERNAME As String, Subject As String, Body As String, AppDate As Date, Duration As Integer)

'Set up the objects required for Automation into lotus notes
Dim Maildb As Object 'The mail database
Dim MailDbName As String 'The persons notes mail database name
Dim CalenDoc As Object 'The calendar entry itself
Dim WorkSpace As Object

Set WorkSpace = CreateObject("Notes.NOTESUIWORKSPACE")

'Get the engineer username and then calculate the mail file name
MailDbName = left$(USERNAME, 1) & right$(USERNAME, (Len(USERNAME) - InStr(1, USERNAME, " ")))
MailDbName = "mail\" & left$(MailDbName, 8) & ".nsf"

'Create a new calender appointment based on template and set the attributes.
Set CalenDoc = WorkSpace.COMPOSEDOCUMENT("SERVERNAME", MailDbName, "Appointment")
CalenDoc.FIELDSETTEXT "AppointmentType", "2"
CalenDoc.FIELDSETTEXT "StartDate", CStr(Format(Date, "dd/mm/yy"))
CalenDoc.FIELDSETTEXT "Duration", CStr(Duration)
CalenDoc.FIELDSETTEXT "Subject", Subject
CalenDoc.FIELDSETTEXT "Body", Body
CalenDoc.Save False, False, False
CalenDoc.Close

Set Maildb = Nothing
Set CalenDoc = Nothing
Set WorkSpace = Nothing
End Sub

redneck
30.04.2004, 10:16
Hallo nouba,

Danke für deine Bemühungen, aber kannst du mir vielleicht noch mitteilen wie ich den Code über Button ausführen kann.

Gruß redneck