By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,285 Members | 1,248 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,285 IT Pros & Developers. It's quick & easy.

What is the Option Strict On replacement for CreateItem?

P: n/a
There are two statements below marked 'ERROR that I would like to recode to
be acceptable to Option Strict On. I tried the two statements at the
bottom, but that was not acceptable. Can anyone Help?

Dim outlook As Outlook.Application

Dim olns As Outlook.NameSpace

Dim apptItem As Outlook.AppointmentItem

Dim mailItem As Outlook.MailItem

outlook = New Outlook.ApplicationClass

olns = outlook.GetNamespace("MAPI")

mailItem = outlook.CreateItem(olMailItem) 'ERROR

apptItem = outlook.CreateItem(olAppointmentItem) 'ERROR

Cannot use statements below because Sub New() is Private:

Dim apptItem As New Outlook.AppointmentItem

Dim mailItem As New Outlook.MailItem

Thanks,

Dean Slindee
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
I think you may have a name space imports problem.

'Assuming:
Imports Microsoft.Office.Core
Imports Microsoft.Office.Interop

'Then:
mailItem = outlook.CreateItem(Outlook.olMailItem)
apptItem = outlook.CreateItem(Outlook.olAppointmentItem)

//I also would suggest changing the variable name (and references to it)
below to something besides outlook to avoid confusion between the variable
name and the Outlook namespace.

Dim outlook As Outlook.Application
"Dean Slindee" <sl*****@charter.net> wrote in message
news:eb*******************@fe04.lga...
There are two statements below marked 'ERROR that I would like to recode
to
be acceptable to Option Strict On. I tried the two statements at the
bottom, but that was not acceptable. Can anyone Help?

Dim outlook As Outlook.Application

Dim olns As Outlook.NameSpace

Dim apptItem As Outlook.AppointmentItem

Dim mailItem As Outlook.MailItem

outlook = New Outlook.ApplicationClass

olns = outlook.GetNamespace("MAPI")

mailItem = outlook.CreateItem(olMailItem) 'ERROR

apptItem = outlook.CreateItem(olAppointmentItem) 'ERROR

Cannot use statements below because Sub New() is Private:

Dim apptItem As New Outlook.AppointmentItem

Dim mailItem As New Outlook.MailItem

Thanks,

Dean Slindee

Nov 21 '05 #2

P: n/a
For Options Strict on, try:

mailItem = CType(outlook.CreateItem(Global.Outlook.OlItemType .olMailItem),
Global.Outlook.MailItem)
apptItem =
CType(outlook.CreateItem(Global.Outlook.OlItemType .olAppointmentItem),
Global.Outlook.AppointmentItem)

HTH
Lee

"Dean Slindee" <sl*****@charter.net> wrote in message
news:eb*******************@fe04.lga...
There are two statements below marked 'ERROR that I would like to recode
to
be acceptable to Option Strict On. I tried the two statements at the
bottom, but that was not acceptable. Can anyone Help?

Dim outlook As Outlook.Application

Dim olns As Outlook.NameSpace

Dim apptItem As Outlook.AppointmentItem

Dim mailItem As Outlook.MailItem

outlook = New Outlook.ApplicationClass

olns = outlook.GetNamespace("MAPI")

mailItem = outlook.CreateItem(olMailItem) 'ERROR

apptItem = outlook.CreateItem(olAppointmentItem) 'ERROR

Cannot use statements below because Sub New() is Private:

Dim apptItem As New Outlook.AppointmentItem

Dim mailItem As New Outlook.MailItem

Thanks,

Dean Slindee

Nov 21 '05 #3

P: n/a
"Dean Slindee" <sl*****@charter.net> schrieb:
There are two statements below marked 'ERROR that I would like to recode
to
be acceptable to Option Strict On. I tried the two statements at the
bottom, but that was not acceptable. Can anyone Help?

Dim outlook As Outlook.Application

Dim olns As Outlook.NameSpace

Dim apptItem As Outlook.AppointmentItem

Dim mailItem As Outlook.MailItem

outlook = New Outlook.ApplicationClass

olns = outlook.GetNamespace("MAPI")

mailItem = outlook.CreateItem(olMailItem) 'ERROR
\\\
mailItem = DirectCast(outlook.CreateItem(...), Outlook.AppointmentItem)
///
apptItem = outlook.CreateItem(olAppointmentItem) 'ERROR


\\\
.... = DirectCast(..., Outlook.MailItem)
///

In addition to that, I suggest to import the 'Outlook' namespace.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4

P: n/a
Herfried,
| In addition to that, I suggest to import the 'Outlook' namespace.

With Outlook (and other Office apps) I normally use an Import Alias, to
avoid conflicts between System.Windows.Forms.Application and the Application
type in the respective office app.

For example with Outlook I normally use:

Imports Outlook = Microsoft.Office.Interop.Outlook

Then my code looks similiar to Dean's...

Hope this helps
Jay

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OT**************@TK2MSFTNGP15.phx.gbl...
| "Dean Slindee" <sl*****@charter.net> schrieb:
| > There are two statements below marked 'ERROR that I would like to recode
| > to
| > be acceptable to Option Strict On. I tried the two statements at the
| > bottom, but that was not acceptable. Can anyone Help?
| >
| > Dim outlook As Outlook.Application
| >
| > Dim olns As Outlook.NameSpace
| >
| > Dim apptItem As Outlook.AppointmentItem
| >
| > Dim mailItem As Outlook.MailItem
| >
| > outlook = New Outlook.ApplicationClass
| >
| > olns = outlook.GetNamespace("MAPI")
| >
| > mailItem = outlook.CreateItem(olMailItem) 'ERROR
|
| \\\
| mailItem = DirectCast(outlook.CreateItem(...), Outlook.AppointmentItem)
| ///
|
| > apptItem = outlook.CreateItem(olAppointmentItem) 'ERROR
|
| \\\
| ... = DirectCast(..., Outlook.MailItem)
| ///
|
| In addition to that, I suggest to import the 'Outlook' namespace.
|
| --
| M S Herfried K. Wagner
| M V P <URL:http://dotnet.mvps.org/>
| V B <URL:http://classicvb.org/petition/>
|
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.