Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

VBA and Lotus Notes: Using VBA to create Notes email with 2 (or more) attachments and have Notes open email for user edit before sending

Posted on 2013-01-25
13
Medium Priority
?
2,644 Views
Last Modified: 2013-12-18
Hi, this is a follow-up to an answered question I had from 2009:

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_24019619.html#a38819051

The code Bill helped me with has worked perfectly over the past few years, but unfortunately, my desktop got rebuilt last weekend and all my apps including Office and Notes were reinstalled.  Now, when I run that same code, I get a run-time error 91: Object variable or With block variable not set at line 71 of ComposeMemo: Call uidoc.GotoField("Body")

Any idea what happened and how can I fix it?

Thank you.

Below is the code:

Sub Test_GIF()
 
  Dim html As String
  Dim attachments(0) As String, imageFiles(0) As String, imageTypes(0) As String, imageTags(0) As String
  html = "<div style='font-size: 10pt; font-family: Arial, Helvetica, sans-serif; font-weight: bold;'><img src='cid:image_1.gif'>This is a test!</div>"
  attachments(0) = "c:\temp\any_file.txt"
  imageFiles(0) = "c:\temp\any_image.gif"
  imageTypes(0) = "image/gif"
  imageTags(0) = "image_1.gif"
  Call ComposeMemo("some.user@acme.com", "Test from Excel", html, attachments, imageFiles, imageTypes, imageTags)
 
End Sub



Sub ComposeMemo(sendto As String, ByVal subject As String, ByVal html As String, attachments() As String, imageFiles() As String, imageTypes() As String, imageTags() As String)
 
  Dim sess As Object, db As Object, doc As Object, stream As Object, ws As Object, uidoc As Object
  Dim mimeBody As Object, mimeHtml As Object, mimeFile As Object, mimeImage As Object, mimeHeader As Object
  Dim i As Integer
  Dim convertMime As Boolean
  Const ENC_QUOTED_PRINTABLE = 1726
  Const ENC_IDENTITY_8BIT = 1729
  Const EMBED_ATTACHMENT = 1454
 
  ' Create an email doc
  Set sess = CreateObject("Notes.NotesSession")
  Set ws = CreateObject("Notes.NotesUiWorkspace")
  Set db = sess.GetDatabase("", "")
  Call db.OpenMail
  Set doc = db.CreateDocument()
  Call doc.ReplaceItemValue("Form", "Memo")
 
  ' add the body as a mime html part
  convertMime = sess.convertMime
  sess.convertMime = False
  Set stream = sess.CreateStream()
  stream.WriteText (html & "<br><br>")
  Set mimeBody = doc.CreateMIMEEntity("Body")
  Set mimeHtml = mimeBody.CreateChildEntity()
  Call mimeHtml.SetContentFromText(stream, "text/html; charset=""iso-8859-1""", ENC_QUOTED_PRINTABLE)
  Call stream.Close
 
  ' add file attachments
  For i = 0 To UBound(attachments)
    Set mimeFile = mimeBody.CreateChildEntity()
    Set mimeHeader = mimeFile.CreateHeader("Content-Transfer-Encoding")
    Call mimeHeader.SetHeaderVal("binary")
    Set mimeHeader = mimeFile.CreateHeader("Content-Disposition")
    Call mimeHeader.SetHeaderVal("attachment; filename=" & attachments(i))
    Call stream.Open(attachments(i), "binary")
    Call mimeFile.SetContentFromBytes(stream, "text/plain", ENC_NONE)
    Call mimeFile.EncodeContent(ENC_IDENTITY_8BIT)
    Call stream.Close
  Next
 
  ' add images referenced by cid tags
  For i = 0 To UBound(imageFiles)
    Set mimeImage = mimeBody.CreateChildEntity()
    Set mimeHeader = mimeImage.CreateHeader("Content-ID")
    Call mimeHeader.SetHeaderVal("<" & imageTags(i) & ">")
    Call stream.Open(imageFiles(i))
    Call mimeImage.SetContentFromBytes(stream, imageTypes(i) & "; name=" + imageTags(i), ENC_IDENTITY_BINARY)
    Call stream.Close
  Next
 
  sess.convertMime = convertMime
  Call doc.CloseMIMEEntities(True, "Body")
  Call doc.Save(True, False)
  Set uidoc = ws.EditDocument(True, doc)
  Call doc.Remove(True)
  ' Exit Sub ' if you don't need the user's signature, you can exit here, otherwise...
  Call uidoc.GotoField("Body")
  Call uidoc.SelectAll
  Call uidoc.Copy
  uidoc.Document.SaveOptions = "0"
  uidoc.Document.MailOptions = "0"
  Call uidoc.Close
 
  ' compose a new memo and paste the body.
  Set uidoc = ws.ComposeDocument(db.Server, db.filePath, "Memo")
  Call uidoc.FieldSetText("EnterSendTo", sendto)
  Call uidoc.FieldSetText("Subject", subject)
  Call uidoc.GotoField("Body")
  Call uidoc.Paste
 
End Sub
0
Comment
Question by:Hammer8
  • 5
  • 5
  • 3
13 Comments
 
LVL 9

Expert Comment

by:shorvath
ID: 38819921
Try explicitly declaring your objects and use the NEW keyword  

replace  

Dim sess As Object, db As Object .... etc

with  

Dim sess As New Domino.NotesSession    
Dim db As New Domino.NotesDatabase
.
.
etc
0
 

Author Comment

by:Hammer8
ID: 38820051
Hi, I tried that, but now get an error message 13 Type Mismatch at:

Set sess = CreateObject("Notes.NotesSession")
0
 
LVL 9

Expert Comment

by:shorvath
ID: 38820086
Set sess = CreateObject("Domino.NotesSession")
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 9

Expert Comment

by:shorvath
ID: 38820094
I assume you made a reference the the correct library..  Just press F2 to se a listing in the Object Browser...
0
 

Author Comment

by:Hammer8
ID: 38820227
Yes, I have references to:

Lotus Domino Objects
Lotus Notes Automation Classes


Now, I get an error 429:  ActiveX component can't create object.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 38821749
The original code seems ok. It could have something to do with rights in the database, or with the fact that the doc is removed wile the uidoc is still in use.

In order to get a quick resulution of your problem, I'll ask Bill in. That is, if i still have his mail address somewhere...
0
 

Author Comment

by:Hammer8
ID: 38821922
That would be much appreciated...thank you.
0
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 2000 total points
ID: 38823695
Mail sent.
0
 
LVL 9

Expert Comment

by:shorvath
ID: 38826479
I suggest you try a test project just to see if all the required objects load and that you can make a connection to the database object.
0
 

Author Comment

by:Hammer8
ID: 38827680
Hi, I had my IT person reinstall Lotus Notes and now, I am getting a different error message.  The first is Lotus Notes itself now gives me a pop up which says Cannot locate Form: Memo.  And after I hit "OK" to that, in VBA, I get error message:  Run-time error '7412':  Notes Error - Cannot locate Default Form.  This occurs at line "Set uidoc = ws.EDITDOCUMENT(True, doc)"

Maybe this helps to isolate the problem?

Thanks you all again!
0
 
LVL 9

Expert Comment

by:shorvath
ID: 38827870
same problem...   Dim ws As Object   won't work..

Try Dim ws As New As NotesUIWorkspace

See this link;

http://www-12.lotus.com/ldd/doc/domino_notes/rnext/help6_designer.nsf/f4b82fbb75e942a6852566ac0037f284/bec4fde193f5dbd885256c54004d61e3?OpenDocument
0
 

Author Comment

by:Hammer8
ID: 38833473
Thank you all for your help.  I'm happy to report that the problem was solved after we "sync'ed/replicated" something called Application templates (NTF)'s.  I'm not sure what those are, but now that it's sync'ed with the server, the macro works as before.  Hopefully someone else with the same problem will be able to find this solution if they are experiencing the same issue.  Again, your help is much appreciated!
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 38838774
That's more or less what I expected: the code was okay, so there was a problem elsewhere (my, really? ;-)). I'd never have guessed that replicating the NTFs would solve it. An application template is a design copy of an application, it's usually the design base of one or more identical applications. The developer uses the template to apply modifications. The template is then used to refresh all databases that are derived from the template. E.g. there is a mail template mail85.ntf with the internal name StdR85Mail; when a new release of Domino is installed and the template is modified, the template is automatically applied to all mail databases.

However, how this solved your problem I fail to see... But I'm glad that it's solved!
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 6 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question