can't call Designer procedure from Form

  • Thread starter Thread starter Geo
  • Start date Start date
G

Geo

Just getting started with add-ins, so please bear with
me... I'm trying to create a COM add-in with VB6 (ActiveX
dll).

I have a timer on a form that calls a simple one-
line 'test' procedure on the "Connect" module of
my "Designer". It chokes telling me that "variable or With
block variable not set". Is there some special way of
declaring the modules that I'm missing?
 
Thanks Ken. Yes, the form code (summarized) looks like
this (Designer module code follows):

----------------------------
Public VBInstance As VBIDE.VBE
Public Connect As Connect

Public Sub Timer1_Timer()
Timer1.Enabled = False
Call Connect.testit
End Sub
----------------

The Designer module (called "Connect") code is:

------------
Public Sub testit()
MsgBox "tested OK"
End Sub
--------

The error I get is "Object variable or With block variable
not set". If I take out the Public declaration
of "Connect" then the error is "object required". I'm
testing this in debug mode via Outlook.

-----Original Message-----
Normally you would put a global procedure in a code module and not in
the Designer. Is the procedure declared as Public?

--
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


Geo said:
Just getting started with add-ins, so please bear with
me... I'm trying to create a COM add-in with VB6 (ActiveX
dll).

I have a timer on a form that calls a simple one-
line 'test' procedure on the "Connect" module of
my "Designer". It chokes telling me that "variable or With
block variable not set". Is there some special way of
declaring the modules that I'm missing?


.
 
I still would put the public code in a code module rather than trying
to run it from the designer, but if you insist you need to things
differently.

Form Code:
Public Sub Timer1_Timer()
Dim clsConnect As Connect

Set clsConnect = New Connect
Timer1.Enabled = False
Call Connect.testit

Set clsConnect = Nothing
End Sub

Designer code:
Public Sub testit()
MsgBox "tested OK"
End Sub

That's not really good code practice though so I encourage you to do
things differently.

--
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
 
The event handlers have to be in class modules or in the designer.

See ItemsCB on the Resources page at www.microeye.com for a COM addin
sample that shows the best practices for Outlook COM addins. It should
answer a lot of your questions.

--
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
 
Don't declare g_objReminder as Private in a class module if you want
to be able to reference it from another module or class or form.
Declare it Public in a code module or you can be very object oriented
and do something like this:

Form:

Private m_objReminder As Outlook.Reminder

Public Property Let ReminderObject(objReminder As Outlook.Reminder)
Set m_objReminder = objReminder
End Property

Sub Form_Unload()
Set m_objReminder = Nothing
End Sub

You can then Load the form and init the property with your reminder
object. One way or the other you need to make the reminder object
visible in scope to the timer form code. I'd suggest studying up on
the rules of scope and when objects and variables are in and out of
scope.

I also don't see why in your form code you are instantiating another
instance of OutAddIn. By doing that you are ensuring that the reminder
object isn't in scope since you are creating an entirely new instance
of OutAddIn.

--
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
 
Your code works here if and only if I don't use a second instance of
the class module where the ReminderFire event is handled.
Instantiating and calling a second instance of the class makes your
module level objects not instantiated within that second class module,
therefore they are Nothing.

That's what I was trying to explain when talking about the scope of
your objects.

Declare the class module as global in a code module:

Public OutAddIn As New clsAddIn

That's the class instance you want to use throughout your code. If you
do that you'll find your module level objects are in scope.

A reminder object within the Reminders search folder is only there
while a reminder is present on the original item. If you check you'll
see that your ReminderObject (while in the Reminders folder) is
actually the original item that has a reminder. However, even with the
reminder dismissed the original item will still exist and your
g_objReminder (and g_Item which is actually the same object) both will
still point to the original object. In your call from the timer object
you'd have to check to see that a reminder was still enabled on the
item (if not it was dismissed) and that the reminder wasn't snoozed
(that would change the reminder time).

Another thing you have to consider is reminders on contact items can
be set but you can't check on the setting using the Outlook object
model. You have to use undocumented CDO 1.21 or Extended MAPI to find
the reminder properties for a contact item.

--
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
 
Back
Top