I have a form that calls a method within a DLL. By clicking a button on the
form, the DLL is instantiated and the SaveOutlookMessage() method invoked.
The DLL code copies messages from Outlook to an HTML file. When I execute
the EXE, which is only the form, and click the button, I get a "Type
Mismatch" error on this line in the form: mailobj.SaveOutlookMessage()
Any suggestions on why I'm getting the type mismatch error?
--Form code
Option Explicit Off
Public Class Form1
Private mailobj As OutlookSaveEmail.SaveOutlookMessage
Private Outlookobj As TestOutlookSaveEmail.Form1
Private Sub instantiate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles instantiate.Click
mailobj = New OutlookSaveEmail.SaveOutlookMessage
mailobj.SaveOutlookMessage() 'this line results in a type mismatch error
End Sub
End Class
--DLL code:
Public Class SaveOutlookMessage
Public Sub SaveOutlookMessage()
Dim fso As Object
Dim txtfile As Object
Dim myOlApp As Object
Dim myNamespace As Object
Dim myFolder As Object
Dim olFolderInbox As Object
Dim i As Integer
Dim myMailItems As String
olFolderInbox = ""
myMailItems = ""
fso = CreateObject("Scripting.FileSystemObject")
myOlApp = CreateObject("Outlook.Application")
myNamespace = myOlApp.GetNamespace("MAPI")
myFolder = myNamespace.GetDefaultFolder(olFolderInbox)
i = 1
Do Until i = 7
If myFolder.Items(i).Subject = "RE: Problem with mail" Then
If Len(myFolder.Items(i).HTMLBody) Then
myMailItems = myFolder.Items(i).HTMLBody
Else
myMailItems = myFolder.Items(i).Body
End If
End If
i = i + 1
Loop
txtfile = fso.CreateTextFile("C:\Myfiles\messages\" & "Testing" & ".html",
True)
txtfile.WriteLine(myMailItems)
txtfile.Close()
txtfile = Nothing
fso = Nothing
myOlApp = Nothing
myNamespace = Nothing
myFolder = Nothing
myMailItems = Nothing
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class
Running .NET 2.0 framework.
Thanks,
Brett