Hello;Hope someone can point me in the right direction. I appreciate any help. I am stuck trying to get a feature working on a database. All the folowing code below is for an agent, “emaildocs”.
A user should be able to select a document, click the menu agent “emaildocs” and the document will be detached (copied) and attached to user email and sent for review. I have it detaching but cannot seem to fetch the user mail account for the attachment
function. I am getting the error “Object Variable not set”.
My humble theory is something to do with
notesUIworkspace and noteswsworkspace going from a view to get user mail file.
Can someone please offer some feedback in simple terms as I am learning this as I go.
Thank you very much in advance.
Declarations:
Dim s_currentsession As NotesSession
Dim db_thisDatabase As Notesdatabase
Dim doc_RecordDoc As Notesdocument
Dim str_runtime As String
Dim int_doccount As Long
Dim int_currentdoc As Long
Dim dc As NotesDocumentCollection
Initilze:
Sub Initialize
Call setup
’ Start with the first row and start looping
Call mainloop
End Sub
Mainloop:
Sub mainloop
Set doc_RecordDoc = dc.GetFirstDocument()
While Not(doc_RecordDoc Is Nothing)
Messagebox doc_RecordDoc.Titleopp(0), MB_OK, "Selecting"
Call detach
Call draft_msg
Call s_currentsession.UpdateProcessedDoc( doc_RecordDoc )
Set doc_RecordDoc = dc.GetNextDocument(doc_RecordDoc)
Wend
End Sub
Setup:
Sub setup
’ Create new objects where necessary and point to the correct view.
Set s_currentsession = New NotesSession
’ Connect to the database, create a query, and execute it.
Set db_thisDatabase = s_currentsession.CurrentDatabase
Set dc = db_thisDatabase.UnprocessedDocuments
End Sub
Detach:
Sub detach
Dim rtitem As Variant
Dim object As NotesEmbeddedObject
Dim handle As Variant
'…set value of doc…
Set rtitem = doc_RecordDoc.GetFirstItem( "deliverable" )
If ( rtitem.Type = RICHTEXT ) Then
Forall o In rtitem.EmbeddedObjects
If ( o.Type = EMBED_ATTACHMENT ) Then
Messagebox o.Source, MB_OK, "Detaching"
Call o.ExtractFile( "c:\temp\" & o.Source )
End If
End Forall
End If
End Sub
Draft_msg:
Sub draft_msg
Dim ws As New notesuiworkspace
Dim session As New notessession
Dim uidoc As notesuidocument
Dim doc As notesdocument
Dim db2 As notesdatabase
Dim view2 As notesview
Dim doc2 As NotesDocument
Dim subj As Variant
Dim note As NotesRichTextItem
Dim item As NotesItem
Dim username As New NotesName(session.UserName)
strUser = username.canonical
server$ = session.GetEnvironmentString ("MailServer", True) 'Get user's home/mail server
mailfile$ = session.GetEnvironmentString ("MailFile", True) 'Get user's mail file name
Set uidoc = ws.currentdocument
Set doc=uidoc.document
Set db2 = session.getdatabase (server$,mailfile$)
’ Set view2 = db2.getview (“Drafts”)
Set doc2 = db2.createdocument
doc2.Form = "Memo"
doc2.Subject ="test"
Call doc2.save(True,False)
Messagebox "A draft message has been created with your selections."
End Sub