Log in

View Full Version : Solved: Passing objects into procedure



JoeMarfice
08-16-2007, 02:28 PM
OK, I feel like a complete dolt here, but for the life of me - I cannot figure out how to pass an object in.

Here's an example program:

' ***********
Sub RemoveDuplicateAppointments()
Dim mapiAppointments As MAPIFolder
Dim itmAppointment As AppointmentItem

Set mapiAppointments = Outlook.Application. _
GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar)

For Each itmAppointment In mapiAppointments.Items
StripDoubleQuotesFromAppointment (itmAppointment)
Next itmContact
End Sub

Sub PlayWithAppointment(itmAppointment As AppointmentItem)
' Do something.
End Sub
' ***********

So, in theory, the subroutine PlayWithAppointment would receive an Appointment Object, and do something with it. But instead, I get the error:

Run-time error '91':
Object variable or With block variable not set.

Can someone steer me to the right path?

TIA, a whole bunch.

JoeMarfice
08-16-2007, 03:01 PM
See?! I *KNEW* I was being a dolt!

Objects must not be enclosed in parentheses when being passed:

' ***********
Sub RemoveDuplicateAppointments()
Dim mapiAppointments As MAPIFolder
Dim itmAppointment As AppointmentItem

Set mapiAppointments = Outlook.Application. _
GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar)

For Each itmAppointment In mapiAppointments.Items
StripDoubleQuotesFromAppointment itmAppointment
' NOTICE I REMOVED THE PARENTHESES IN THE ABOVE LINE!
Next itmContact
End Sub

Sub PlayWithAppointment(itmAppointment As AppointmentItem)
' Do something.
End Sub
' ***********

Paul_Hossler
08-21-2007, 12:36 PM
Try using 'Call ....' as in

Call StripDoubleQuotesFromAppointment (itmAppointment)

and see if that works also

Paul