Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all

I m facing a problem with creating Instance of Categories Interface.
I copy this code from MSDN and try to execute in vb.net application.

Dim instance As _Categories
Dim Name As String
Dim Color As Object
Dim ShortcutKey As Object
Dim returnValue As Category

returnValue = instance.Add(Name, Color, ShortcutKey)


But it is showing Error "Object reference not set to an instance of an object."

Here is the link of msdn. Can anyone solve this problem and give me suggestion with the help of code...

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook._categories.add.aspx[^]

Plz help it's urgent.

Regards
DC
Posted

1 solution

instance is not set to anything, that's why you get the error.

Try this code:

Dim instance As Categories<br />Dim Name As String<br />Dim Color As OlColor<br />Dim ShortcutKey As OlCategoryShortcutKey<br /><br />Dim returnValue As Category<br /><br />Dim f As NameSpace<br />Set f = Application.GetNamespace("MAPI")<br />Set instance = f.Categories<br />Color = olColorFuchsia<br />Name = "MyCategory"<br />ShortcutKey = olCategoryShortcutKeyNone<br />Set returnValue = instance.Add(Name, Color, ShortcutKey)

 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900