473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Help with Type Mismatch

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
Nov 21 '05 #1
1 2777
Brett wrote:
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?


From a quick glance at your code, I'm guessing that the error is actually
inside the SaveOutlookMessage procedure, rather than in the line where it's
called, so if you adjust your exception handling then you can track it down
more precisely. What I'd also recommend is that you use:
Option Strict On
Option Explicit On
at the start of each module, and then use early binding, rather than having
declarations like "Dim fso As Object". That way, any problems will show up
at compile-time rather than at run-time.

John
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: LJgrnl | last post by:
I've got a type mismatch error that's driving me nutty. Variable blnNoData has the initial value False. If a recordset comes back empty (both .EOF and ..BOF are true) then blnNoData is set to...
6
by: Howard Kaikow | last post by:
I'm doing a VB 6 project in which I am trying to protect against type mismatch errors. Is the process any different in VB .NET? Here's what I'm doing in VB 6. I have an ActiveX DLL. The...
9
by: isaac2004 | last post by:
hi i have a page that inclued a SQL statement that takes a user input from a form and displays the request from the database. every time i try to open the page i get an error message that says Data...
6
by: isaac2004 | last post by:
hello i am getting a type mismatch for a page i am trying to write. any help would be great source code <%@ Language=VBScript %> <% Option Explicit %> <!--#include...
2
by: Rehan | last post by:
Hi there! Please help me out here. I am an inch away from completing my assignment. I am very new to VBA but i have very less time to be efficient at it. I am getting a type mismatch error...
5
by: Davros9 | last post by:
Trying to get Regular Expressions working....... ---------------- Public Function SepString(InField As String) As String ''seperates on space and comma Dim RE As New RegExp Dim Matches As...
47
by: Jo | last post by:
Hi there, I'm Jo and it's the first time I've posted here. I'm in process of creating a database at work and have come a little unstuck.....I'm a bit of a novice and wondered if anyone could...
9
by: sara | last post by:
Hi - I have code (below) that ran as recently as Monday. We decided to change the location for the output reports, and now the code errors (13 Type Mismatch) on the query. The query runs fine...
2
by: embz | last post by:
this post concerns three pages. 1. this page: http://www.katherine-designs.com/sendemail.php i get the following errors: a lot of it seems to deal with the PHP code i inserted to the page....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.