Error 91

J

James

I keep on getting an error that says: Object variable or With block
variable not set (Error 91) I looked it up and can't seem to fix the
problem. Do you know of anything? The code is below that I am useing.
Go easy on me I am new to the outlook side of things.


Private Sub btnOutlook_Click()
On Error GoTo Err_btnOutlook_Click

Dim objOApp As New Outlook.Application
Dim objAppt As AppointmentItem
Dim oExp As Outlook.Explorer
Dim i As Long
Dim j As Long
Dim oItems As Outlook.Items
Dim oFilter As Outlook.Items
Dim sEventID As Object

Set oItems = objOApp.Session.GetDefaultFolder(olFolderCalendar).Items
Set oFilter = oItems.Restrict("[Subject] = '" & sEventID & "'")
Set sEventID = Me.EventID
Set objOApp = New Outlook.Application
Set objAppt = objOApp.CreateItem(olAppointmentItem)
Set oExp = objOApp.Session.GetDefaultFolder(olFolderInbox).GetExplorer

If oFilter.Count > 0 Then
'item already exists with that value
j = oFilter.Count
For i = j To 1 Step -1
Set oAppt = oFilter(i)
objAppt.Delete
Next i

Else

With objAppt
.ReminderOverrideDefault = True
.ReminderSet = True
.ReminderMinutesBeforeStart = 1440 '1 Day
.Subject = EventID
.Importance = 2 ' high
.Start = PUDate
.End = DODate
.Body = PULocation & " - " & DOLocation & " - " & Notes & " - "
& EventDescription
.MeetingStatus = 1
.ResponseRequested = False
.Save 'Comment out if you do not want message saved to your
sent items folder
.Send
MsgBox "The event has been sent."

End With

End If

Set objOApp = Nothing
Set objAppt = Nothing
Set oExp = Nothing
Set oItems = Nothing
Set oFilter = Nothing
Set sEventID = Nothing

Exit_btnOutlook_Click:
Exit Sub

Err_btnOutlook_Click:
MsgBox Err.Description
Resume Exit_btnOutlook_Click
End Sub

Re: Finding an Outlook entry.
From: James Simmons

Thank you for answering my question. I had this posted in many other
newsgroups but no reply. I will try this and if I have anymore problems
I will post another thread.


Re: Finding an Outlook entry.
From: Ken Slovak - [MVP - Outlook]
Date Posted: 7/17/2003 3:17:00 PM

Please post some of the preceding message thread when you use that
horrid DevelopersDex interface, it doesn't do that and it makes it
very hard to follow threads. Thanks.

An If statement forms a block, all the code after If <condition> Then
to the End If is executed if <condition> is True.

In this case if you find an item and you want to delete it get the
item and use the .Delete method on it. If you want to add a new item
use an Else clause which will be executed when the If test fails.

Dim oAppt As Outlook.AppointmentItem
Dim i As Long
Dim j As Long

If oFilter.Count > 0 Then
'item already exists with that value
j = oFilter.Count
For i = j To 1 Step -1
Set oAppt = oFilter(i)
oAppt.Delete
Next i
Else
'no item, add it, you have code for that already
End If


--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm
 
G

George Hester

I would have done:

Dim objOApp as Outlook.Application
Set objOApp = New Outlook.Application

--
George Hester
__________________________________
James said:
I keep on getting an error that says: Object variable or With block
variable not set (Error 91) I looked it up and can't seem to fix the
problem. Do you know of anything? The code is below that I am useing.
Go easy on me I am new to the outlook side of things.


Private Sub btnOutlook_Click()
On Error GoTo Err_btnOutlook_Click

Dim objOApp As New Outlook.Application
Dim objAppt As AppointmentItem
Dim oExp As Outlook.Explorer
Dim i As Long
Dim j As Long
Dim oItems As Outlook.Items
Dim oFilter As Outlook.Items
Dim sEventID As Object

Set oItems = objOApp.Session.GetDefaultFolder(olFolderCalendar).Items
Set oFilter = oItems.Restrict("[Subject] = '" & sEventID & "'")
Set sEventID = Me.EventID
Set objOApp = New Outlook.Application
Set objAppt = objOApp.CreateItem(olAppointmentItem)
Set oExp = objOApp.Session.GetDefaultFolder(olFolderInbox).GetExplorer

If oFilter.Count > 0 Then
'item already exists with that value
j = oFilter.Count
For i = j To 1 Step -1
Set oAppt = oFilter(i)
objAppt.Delete
Next i

Else

With objAppt
.ReminderOverrideDefault = True
.ReminderSet = True
.ReminderMinutesBeforeStart = 1440 '1 Day
.Subject = EventID
.Importance = 2 ' high
.Start = PUDate
.End = DODate
.Body = PULocation & " - " & DOLocation & " - " & Notes & " - "
& EventDescription
.MeetingStatus = 1
.ResponseRequested = False
.Save 'Comment out if you do not want message saved to your
sent items folder
.Send
MsgBox "The event has been sent."

End With

End If

Set objOApp = Nothing
Set objAppt = Nothing
Set oExp = Nothing
Set oItems = Nothing
Set oFilter = Nothing
Set sEventID = Nothing

Exit_btnOutlook_Click:
Exit Sub

Err_btnOutlook_Click:
MsgBox Err.Description
Resume Exit_btnOutlook_Click
End Sub

Re: Finding an Outlook entry.
From: James Simmons

Thank you for answering my question. I had this posted in many other
newsgroups but no reply. I will try this and if I have anymore problems
I will post another thread.


Re: Finding an Outlook entry.
From: Ken Slovak - [MVP - Outlook]
Date Posted: 7/17/2003 3:17:00 PM

Please post some of the preceding message thread when you use that
horrid DevelopersDex interface, it doesn't do that and it makes it
very hard to follow threads. Thanks.

An If statement forms a block, all the code after If <condition> Then
to the End If is executed if <condition> is True.

In this case if you find an item and you want to delete it get the
item and use the .Delete method on it. If you want to add a new item
use an Else clause which will be executed when the If test fails.

Dim oAppt As Outlook.AppointmentItem
Dim i As Long
Dim j As Long

If oFilter.Count > 0 Then
'item already exists with that value
j = oFilter.Count
For i = j To 1 Step -1
Set oAppt = oFilter(i)
oAppt.Delete
Next i
Else
'no item, add it, you have code for that already
End If


--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm


James Simmons said:
After I collect the one I am trying to then what do I do. Do I use the
If statement on that and then at the end use the Then statement and then
put the code to delete the record and add the new one?
 
S

Sue Mosher [MVP]

Which statement produces this error? What is the context -- what application are you using to run this code?

Looks to me like this is the problem (and it's basic coding, not an Outlook quirk):
Set oFilter = oItems.Restrict("[Subject] = '" & sEventID & "'")
Set sEventID = Me.EventID

You're running Restrict before you have the value of one of the terms in the expression, and you're trying to set a string variable as an object. Try this instead:

sEventID = Me.EventID
Set oFilter = oItems.Restrict("[Subject] = '" & sEventID & "'")

What is Me?

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm

James said:
I keep on getting an error that says: Object variable or With block
variable not set (Error 91) I looked it up and can't seem to fix the
problem. Do you know of anything? The code is below that I am useing.
Go easy on me I am new to the outlook side of things.


Private Sub btnOutlook_Click()
On Error GoTo Err_btnOutlook_Click

Dim objOApp As New Outlook.Application
Dim objAppt As AppointmentItem
Dim oExp As Outlook.Explorer
Dim i As Long
Dim j As Long
Dim oItems As Outlook.Items
Dim oFilter As Outlook.Items
Dim sEventID As Object

Set oItems = objOApp.Session.GetDefaultFolder(olFolderCalendar).Items
Set oFilter = oItems.Restrict("[Subject] = '" & sEventID & "'")
Set sEventID = Me.EventID
Set objOApp = New Outlook.Application
Set objAppt = objOApp.CreateItem(olAppointmentItem)
Set oExp = objOApp.Session.GetDefaultFolder(olFolderInbox).GetExplorer

If oFilter.Count > 0 Then
'item already exists with that value
j = oFilter.Count
For i = j To 1 Step -1
Set oAppt = oFilter(i)
objAppt.Delete
Next i

Else

With objAppt
.ReminderOverrideDefault = True
.ReminderSet = True
.ReminderMinutesBeforeStart = 1440 '1 Day
.Subject = EventID
.Importance = 2 ' high
.Start = PUDate
.End = DODate
.Body = PULocation & " - " & DOLocation & " - " & Notes & " - "
& EventDescription
.MeetingStatus = 1
.ResponseRequested = False
.Save 'Comment out if you do not want message saved to your
sent items folder
.Send
MsgBox "The event has been sent."

End With

End If

Set objOApp = Nothing
Set objAppt = Nothing
Set oExp = Nothing
Set oItems = Nothing
Set oFilter = Nothing
Set sEventID = Nothing

Exit_btnOutlook_Click:
Exit Sub

Err_btnOutlook_Click:
MsgBox Err.Description
Resume Exit_btnOutlook_Click
End Sub

Re: Finding an Outlook entry.
From: James Simmons

Thank you for answering my question. I had this posted in many other
newsgroups but no reply. I will try this and if I have anymore problems
I will post another thread.


Re: Finding an Outlook entry.
From: Ken Slovak - [MVP - Outlook]
Date Posted: 7/17/2003 3:17:00 PM

Please post some of the preceding message thread when you use that
horrid DevelopersDex interface, it doesn't do that and it makes it
very hard to follow threads. Thanks.

An If statement forms a block, all the code after If <condition> Then
to the End If is executed if <condition> is True.

In this case if you find an item and you want to delete it get the
item and use the .Delete method on it. If you want to add a new item
use an Else clause which will be executed when the If test fails.

Dim oAppt As Outlook.AppointmentItem
Dim i As Long
Dim j As Long

If oFilter.Count > 0 Then
'item already exists with that value
j = oFilter.Count
For i = j To 1 Step -1
Set oAppt = oFilter(i)
oAppt.Delete
Next i
Else
'no item, add it, you have code for that already
End If


--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm


James Simmons said:
After I collect the one I am trying to then what do I do. Do I use the
If statement on that and then at the end use the Then statement and then
put the code to delete the record and add the new one?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top