Setting the withevents of a commandbuton in vb6 add-in

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello

I have been wondering if there is a way to set the withevents of a
commandbuton in an add-in (vb6) for an outlook custom form.

Example:
Private WithEvents cmdtest As CommandButton

Private Sub objApptItem_Open(Cancel As Boolean)
Dim objpng As UserForm
Select Case objApptItem.FormDescription.Name
Case Is = "Planner"
Set objpng =
objApptItem.GetInspector.ModifiedFormPages("Planning")
Set cmdtest = objpng.Controls("cmdActieviteit") ‘Here I get a error
End Select
End Sub
If I run the code I get an error message type mismatch (error 13)

Steve
Sorry for my English
 
UserForm? That's a VBA thing, it has no relation to any Outlook forms. Try
setting that as an Object and see what happens.
 
Hi Ken

This is not the solution to my problem.
I get the same error.


Thanks
Steve

"Ken Slovak - [MVP - Outlook]" schreef:
 
Sorry, I misread your original message.

If the button was created when the form was designed you can only handle its
Click events within the form code. To do what you want you'd need to create
the button in the COM addin using the Inspector.CommandBars collection. Then
you could handle the Click events for that button in the COM addin.

An alternative would be to use unsupported methods in the form code to call
a procedure that was public in the COM addin from the form code. I prefer
the pure COM addin approach, it gives you more control.
 
Thanks Ken

Creating com add-ins is new stuff for me.
So you are saying I should create the controls I want to use when the form
loads? Will this not slow down the form?


Remark:
I've been programming in vba for over a year now (Access,Excel,Word) but
Outlook is new for me. I've found It strange that wen making forms in outlook
they are in vbscript.

Microsoft has great programming tools, but the first time I opened the form
code editor I was shocked.

My first impression: this cannot be it am doing something wrong, has time
stood still or have they forgot to upgrade this!






"Ken Slovak - [MVP - Outlook]" schreef:
 
No, I'm definitely not saying to create controls on the form when it opens.
If you add controls such as textboxes, drop-downs and so on to a form on the
fly it becomes one-offed and will create lots of problems. I suggested
creating a button in code (Office.CommandBarButton) on the fly from a COM
addin. Completely different.

A button created within a form when you design the form is a CommandButton,
not something that will live on the menu bar or a custom toolbar or a
built-in toolbar such as Standard. It would live in the body of the form
itself. That sort of button click can only be handled within the form code,
with all code written in VBScript and the form then published as a custom
form.

I'd go to www.outlookcode.com and start looking at all the information there
about COM addins, creating buttons and also on form design and coding to
start getting a handle on your various options and how to go about things.

Outlook forms design and coding have been the land that time forgot. The
sorry excuse for an editor there, a slightly beefed up Notepad and all the
other lacks make things a throwback to the coding days of DOS 3.1. Many of
us design and test our forms code using Outlook VBA to take advantage of the
better editor, intellisense and the superior debugging. Then we convert the
code to VBScript by commenting out all the As clauses of declarations,
convert references to getting the current item to Item and use Application
to refer to the Outlook.Application object (no change needed from Outlook
VBA code) to get the code to run as VBScript.
 
Hello Ken

Thanks for helping me but I still got one small remark:
You said:
That sort of button click can only be handled within the form code,
with all code written in VBScript and the form then published as a custom
form.

But you can use the WithEvents of a control from a custom form in
ThisOutlookSession of the vba project and use the events in vba.
This way you get all the events, not only the click event.
No vbscript is needed in the forms.

And that’s why I was wondering if it’s possible to use this in vb6 com
add-inn and also if it is the proper way to program forms.

From reading your last mail and the book from Sue Mosher this probable isn’t
the best way to program custom forms?



Steve


"Ken Slovak - [MVP - Outlook]" schreef:
 
If you expect to get any events from the Forms 2.0 controls used in custom
forms other than the Click event don't rely on it. Even external ActiveX
controls placed on a form don't reliably fire events other than Click.

It all depends on what sort of button you want to add. If it's an
Office.CommandBarButton there's no problem with handling events in a COM
addin but you can't handle those events in form code. While you might be
able to handle some events in ThisOutlookSession for forms controls the
methods aren't supported and aren't guaranteed to work and to work at all in
later versions of Outlook. Not something I'd want to rely on.
 
Back
Top