Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook 2003 "Hello World" command button 1

Status
Not open for further replies.

flek0s

Programmer
Apr 14, 2005
4
GB
Hello. Could anyone out there help me with a basic problem. I normally program in C, with some knowledge and experience of VB, but have a need to develop some M$ Outlook functionality using an Outlook 2003 form that I have developed.

I have put a command button on the form but unlike Access where I go to the properties of the button to access the click event I see no event list. I have tried Tools|Macro|VBeditor and on finding no module there with a click event for the command button I have written a simple 1 line event handler which works when run from the editor:

Public Sub CommandButton2_Click()
MsgBox "Helo World"
End Sub

Can anyone tell me why clicking the command button doesn't run the code, why the event boilerplate wasn't added for me on adding the button, or even simply what I need to do to get at this buttons click event. I know it is a simple problem but feel this would be of interest to others.

Thanks in anticipation
flek0s

 
Hi,

Did you try double-clicking the button? This should expose the code sheet w/ events et al.

Skip,

[glasses] [red]Be advised:[/red]When Viscounts were guillotined just as they were disclosing where their jewels were hidden, it shows to go that you should...
Never hatchet your Counts before they chicken! [tongue]
 
Thanks for the reply but I have tried double clicking with the form in design view and get nothing. I have tried Rclick|Properties and ust get a window with 3 tabs and no events. The form is a modified Contacts form saved to a Contacts directory.
 
I assume that you have already created a form called UserForm1 containing a command button named CommandButton1. To get it to do something, I did the following:

1) ALT + F11 to open the VBA Editor
2) CTRL + R to display the Project Explorer
3) Right-click UserForm1 (or whatever you called it) to display the user form
4) Right-click the command button, choose View Code to get the click event sub. Paste the following code there:
Code:
Private Sub CommandButton1_Click()
MsgBox "Hello world"
End Sub
5) Doubleclick ThisOutlookSession in the Project Explorer to display its code pane
6) Paste the following code there:
Code:
Sub DisplayForm()
UserForm1.Show
End Sub
7) ALT + F11 to return to Outlook user interface
8) ALT + F8 to display the macro selector
9) Choose the DisplayForm sub and click the "Run" button
10) Click on CommandButton1. You should get the "Hello world" message box

Brad
 
Many thanks for the post. It has cleared things a little. My original form was designed by opening a contact and pressing Tools|Form|"Design this form" then saving it as HKform to a new contacts directory called HKcontacts. On going to VB there was a project created but no form hence no events.

Your response indicated a new form in the project was what was needed and this does work as I expected but without the existing Contacts fields which are what I was hoping to use along with my own specific fields. The aim of the button on the form is eventually to use data in the fields to set an appointment in the calendar.

Is it possible to have the best of both worlds ie a HKcontacts form with address fields etc and a working command button?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top