Consulting

Results 1 to 4 of 4

Thread: OpenSharedItem Opening a custom form msg is always blank

  1. #1
    VBAX Regular
    Joined
    Aug 2015
    Posts
    8
    Location

    OpenSharedItem Opening a custom form msg is always blank

    I trying to open a custom form message saved to disk but all I get a blank message. The message header appears correct so I assume I have got the correct message.

    When opening the same custom form msg from Explorer it all works fine.

    Here is the code:

    Private Sub PrintPreviewCustomFormMsgFromSavedDiskFile_Click()
        Dim oOLapp As Outlook.Application
        Dim oMapi As Outlook.NameSpace
        Dim oInspector As Outlook.Inspector
        Dim oCB As Office.CommandBars
        Dim oItem As Outlook.MailItem
        Dim MyPath As String
        
        MyPath = "C:\temp\Custom Form Example 1.msg" ' Form opens/displays correctly from Explorer
        
        Set oOLapp = GetObject(, "Outlook.Application")
        Set oMapi = oOLapp.GetNamespace("MAPI")
        
        Set oItem = oMapi.OpenSharedItem(MyPath) ' Either this or the next ...
        Set oItem = oOLapp.Session.OpenSharedItem(MyPath) ' but not both of course
    
    
        oItem.Display ' Displays blank message ?
        
        Set oInspector = oOLapp.ActiveInspector
        Set oCB = oInspector.CommandBars
    
    
        oCB.ExecuteMso ("FilePrintPreview") ' A blank message results in a blank preview !
        Set oCB = Nothing
        Set oInspector = Nothing
    End Sub
    Any ideas how this should be done correctly?

  2. #2
    VBAX Regular
    Joined
    Aug 2015
    Posts
    8
    Location
    In addition stepping through the code and comparing a MailItem object referenced in a pst store to one opened from a saved file location (using OpenSharedItem) reveals the ModifiedFormPages and UserProperties are all missing!

    Hence why it doesn't display the form.

  3. #3
    VBAX Regular
    Joined
    Aug 2015
    Posts
    8
    Location
    Further if I move the opened MailItem to a Folder ("Drafts") and then re-open it from the folder then it works!

        Set oOLapp = GetObject(, "Outlook.Application")
        Set oFolder = oOLapp.GetNamespace("MAPI").Folders(oMapi.DefaultStore.DisplayName).Folders("Drafts")
        
        oItem.Move oFolder
        oItem.Close olDiscard
        
        Set oItem = oFolder.Items(1) ' Assumes Drafts was empty prior to moving item
        oItem.Display ' Now displays correctly
    The issue I know have is I don't know when the user has finished viewing the MailItem and so have no idea when to clear up the (Temporary) Folder.

    Is there a way to automatically delete a MailItem on closing?

  4. #4
    VBAX Regular
    Joined
    Aug 2015
    Posts
    8
    Location
    The trick was to move the MailItem into a temporary Folder (Deleted Items) and use the MailItem object returned by the move.
    The clearing up issue becomes irrelevant.

    complete code follows:

    Private Sub PrintPreviewCustomFormMsgFromSavedDiskFile_Click()
        Dim oOLapp As Outlook.Application
        Dim oMapi As Outlook.NameSpace
        Dim oInspector As Outlook.Inspector
        Dim oCB As Office.CommandBars
        Dim oItem As Outlook.MailItem
        Dim oFolder As Outlook.Folder
        Dim oItems As Outlook.Items
        Dim MyPath As String
        
        MyPath = "C:\temp\Custom Form Example 1.msg"
        
        Set oOLapp = GetObject(, "Outlook.Application")
        Set oMapi = oOLapp.GetNamespace("MAPI")
        Set oFolder = oOLapp.GetNamespace("MAPI").Folders(oMapi.DefaultStore.DisplayName).Folders("Deleted Items")
        
        Set oItem = oOLapp.Session.OpenSharedItem(MyPath)
        Set oItem = oItem.Move(oFolder)
        oItem.Display
        
        Set oInspector = oOLapp.ActiveInspector
        Set oCB = oInspector.CommandBars
    
    
        oCB.ExecuteMso ("FilePrintPreview")
        
        Set oCB = Nothing
        Set oInspector = Nothing
    End Sub

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •