PC Review


Reply
Thread Tools Rating: Thread Rating: 2 votes, 3.00 average.

Selected date on calendar

 
 
Marc Weichhold
Guest
Posts: n/a
 
      21st Dec 2009
Hello,

I am trying to get the selected date from the calendar month view. I already
learned that the calendar view object itself does not provide any means to
get that data, however, I found Sue Moshers solution on

http://www.outlookcode.com/codedetail.aspx?id=616

Basically, it fetches the command for a new appointment, executes it (so the
new appointment form would open), reads the start and end date from the form
and closes it again. The problem here is that the execute command does not
"work" - there is no new appointment form that opens. No error message, no
exception, just nothing is happening.

Several other readers had that problem, too, and the solution seemed to be
that the command bars had to be reset. But I did not change any command bars
here (no custom commands yet), so I can not reset them.

Can anyone help me?

Marc

 
Reply With Quote
 
 
 
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      21st Dec 2009
The command being executed is the New, Appointment command on the Standard
toolbar. Is that being displayed and are you displaying a calendar folder
when you execute your code?

What if you switch the command button and try using 1992 as the button ID to
execute, does that work? That's the Actions, New Appointment button.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Marc Weichhold" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> I am trying to get the selected date from the calendar month view. I
> already learned that the calendar view object itself does not provide any
> means to get that data, however, I found Sue Moshers solution on
>
> http://www.outlookcode.com/codedetail.aspx?id=616
>
> Basically, it fetches the command for a new appointment, executes it (so
> the new appointment form would open), reads the start and end date from
> the form and closes it again. The problem here is that the execute command
> does not "work" - there is no new appointment form that opens. No error
> message, no exception, just nothing is happening.
>
> Several other readers had that problem, too, and the solution seemed to be
> that the command bars had to be reset. But I did not change any command
> bars here (no custom commands yet), so I can not reset them.
>
> Can anyone help me?
>
> Marc


 
Reply With Quote
 
 
 
 
Marc Weichhold
Guest
Posts: n/a
 
      22nd Dec 2009
Hello Ken.

> The command being executed is the New, Appointment command on the Standard
> toolbar. Is that being displayed and are you displaying a calendar folder
> when you execute your code?
>

Yes, I am displaying the calendar month view when the code is executed and
the command (New, Appointment) is displayed on the standard toolbar.

> What if you switch the command button and try using 1992 as the button ID
> to execute, does that work? That's the Actions, New Appointment button.
>

I tried it and the behavior is the same as before. The execute command does
not open the appointment form and I get no error or exception.

The "funny" part is, for testing purposes I changed the caption of the
command right before I call the execute method - and that works. The caption
is changed, but the execute method is still without effect.

Marc

PS: Btw, if that is important, I am using Outlook 2007 with Exchange Server
2007 and a Visual Studio 2008 Developer Edition. The AddIn language is C#.

 
Reply With Quote
 
Marc Weichhold
Guest
Posts: n/a
 
      22nd Dec 2009
Hello,

one more information. I tried the code from Sue as a VBA macro - and it
worked.

Strange...

Marc

 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      22nd Dec 2009
Now I'm confused.

The code Sue had up is an Outlook VBA macro. What were you trying it as
previously?

If the code wasn't running inside the Outlook VBA project it would never
work as written, the Application object referenced wouldn't be an
Outlook.Application object.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Marc Weichhold" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> one more information. I tried the code from Sue as a VBA macro - and it
> worked.
>
> Strange...
>
> Marc


 
Reply With Quote
 
Marc Weichhold
Guest
Posts: n/a
 
      23rd Dec 2009
Hello Ken,

> The code Sue had up is an Outlook VBA macro. What were you trying it as
> previously?
>
> If the code wasn't running inside the Outlook VBA project it would never
> work as written, the Application object referenced wouldn't be an
> Outlook.Application object.
>


I used the code in a VSTO-AddIn written in C#. Of course, I made some
changes so it would compile and run. It is not that hard, after all I GET
the right button. I can read its properties, even change them. All that does
not work - in the C#-AddIn - is the Execute-method.

For C# the code changes to:

// Application is of type Microsoft.Office.Interop.Outlook.Application
Outlook.Explorer objExpl = Application.ActiveExplorer();
if(objExpl != null)
{
Outlook.Folder objFolder = (Outlook.Folder)objExpl.CurrentFolder;
if(objFolder.DefaultItemType == Outlook.OlItemType.olAppointmentItem)
{
Office.CommandBarButton objCB =
(Office.CommandBarButton)objExpl.CommandBars.FindControl(Type.Missing, 1106,
Type.Missing, Type.Missing);
if(objCB != null)
{
objCB.Execute();
Outlook.AppointmentItem objAppt =
(Outlook.AppointmentItem)Application.ActiveInspector().CurrentItem;
DateTime dtStart = objAppt.Start;
DateTime dtEnd = objAppt.End;
((Outlook._AppointmentItem)objAppt).Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olDiscard);
}
}
}

And as I said, if I place

objCB.Caption = "BlahBlah";

before

objCB.Execute();

then the caption of the button is changed.

Marc

 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      23rd Dec 2009
If you were to breakpoint on the line:

DateTime dtStart = objAppt.Start;

does an Inspector ever get opened with the appointment?

I just tried your code and it works here with no problems with Outlook 2007
and a VSTO addin written in C#. I fired the code from a button click in an
Explorer window, the code ran from my Explorer wrapper class. About the only
change I made was to just use the class level Explorer object in the wrapper
and not use an Application object to get ActiveExplorer(). Other than that
my code was a copy and paste of yours. So I'm not sure why it's not working
for you.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Marc Weichhold" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello Ken,
>
>> The code Sue had up is an Outlook VBA macro. What were you trying it as
>> previously?
>>
>> If the code wasn't running inside the Outlook VBA project it would never
>> work as written, the Application object referenced wouldn't be an
>> Outlook.Application object.
>>

>
> I used the code in a VSTO-AddIn written in C#. Of course, I made some
> changes so it would compile and run. It is not that hard, after all I GET
> the right button. I can read its properties, even change them. All that
> does not work - in the C#-AddIn - is the Execute-method.
>
> For C# the code changes to:
>
> // Application is of type Microsoft.Office.Interop.Outlook.Application
> Outlook.Explorer objExpl = Application.ActiveExplorer();
> if(objExpl != null)
> {
> Outlook.Folder objFolder = (Outlook.Folder)objExpl.CurrentFolder;
> if(objFolder.DefaultItemType == Outlook.OlItemType.olAppointmentItem)
> {
> Office.CommandBarButton objCB =
> (Office.CommandBarButton)objExpl.CommandBars.FindControl(Type.Missing,
> 1106, Type.Missing, Type.Missing);
> if(objCB != null)
> {
> objCB.Execute();
> Outlook.AppointmentItem objAppt =
> (Outlook.AppointmentItem)Application.ActiveInspector().CurrentItem;
> DateTime dtStart = objAppt.Start;
> DateTime dtEnd = objAppt.End;
>
> ((Outlook._AppointmentItem)objAppt).Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olDiscard);
> }
> }
> }
>
> And as I said, if I place
>
> objCB.Caption = "BlahBlah";
>
> before
>
> objCB.Execute();
>
> then the caption of the button is changed.
>
> Marc


 
Reply With Quote
 
Marc Weichhold
Guest
Posts: n/a
 
      24th Dec 2009
Hello Ken,

> If you were to breakpoint on the line:
>
> DateTime dtStart = objAppt.Start;
>
> does an Inspector ever get opened with the appointment?
>

No, there is no Inspector opened at all. The code does throw an exception at
the line

Outlook.AppointmentItem objAppt =
(Outlook.AppointmentItem)Application.ActiveInspector().CurrentItem;

because the method ActiveInspector() returns null. And that's why it would
never reach a breakpoint at the line with dtStart. If I understood it right,
the button's Execute-method is supposed to open a new Inspector object
(which then does open the appointment form). But that never happens, so
there is no ActiveInspector at all after the Execute command. The container
Application.Inspectors is also empty at the point (Count = 0).

> I just tried your code and it works here with no problems with Outlook
> 2007 and a VSTO addin written in C#. I fired the code from a button click
> in an Explorer window, the code ran from my Explorer wrapper class. About
> the only change I made was to just use the class level Explorer object in
> the wrapper and not use an Application object to get ActiveExplorer().
> Other than that my code was a copy and paste of yours. So I'm not sure why
> it's not working for you.
>

Beats me, too. From your experience, would you really think that the
Explorer object is the "problem"? I mean, after all I can manipulate the
button object that I get from the Explorer's command bars...

Marc

PS: Happy Holidays.

 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      24th Dec 2009
I have no idea what the problem is since the same code worked perfectly
here. I tested it in Outlook 2007, with a VSTO addin written in C# with your
code. That's about as close as I can get to whatever your setup is.

Are you running any Outlook addins at all? I'd disable any that might be
running just on the off chance that some other addin is messing up yours.
But I wouldn't put money on that being the problem.

Happy holidays to you too, and to everyone here.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Marc Weichhold" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello Ken,
>
>> If you were to breakpoint on the line:
>>
>> DateTime dtStart = objAppt.Start;
>>
>> does an Inspector ever get opened with the appointment?
>>

> No, there is no Inspector opened at all. The code does throw an exception
> at the line
>
> Outlook.AppointmentItem objAppt =
> (Outlook.AppointmentItem)Application.ActiveInspector().CurrentItem;
>
> because the method ActiveInspector() returns null. And that's why it would
> never reach a breakpoint at the line with dtStart. If I understood it
> right, the button's Execute-method is supposed to open a new Inspector
> object (which then does open the appointment form). But that never
> happens, so there is no ActiveInspector at all after the Execute command.
> The container Application.Inspectors is also empty at the point (Count =
> 0).
>
>> I just tried your code and it works here with no problems with Outlook
>> 2007 and a VSTO addin written in C#. I fired the code from a button click
>> in an Explorer window, the code ran from my Explorer wrapper class. About
>> the only change I made was to just use the class level Explorer object in
>> the wrapper and not use an Application object to get ActiveExplorer().
>> Other than that my code was a copy and paste of yours. So I'm not sure
>> why it's not working for you.
>>

> Beats me, too. From your experience, would you really think that the
> Explorer object is the "problem"? I mean, after all I can manipulate the
> button object that I get from the Explorer's command bars...
>
> Marc
>
> PS: Happy Holidays.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Personal Calendar Item copied to a selected public folder calendar =?Utf-8?B?V2FuZGE=?= Microsoft Outlook VBA Programming 1 1st Nov 2006 07:57 PM
i have two date fileds Opend date Due date, can i set default on due date so, its always = to open date on my data entry form1 Urgent Mike Saifie Microsoft Access Form Coding 1 9th Mar 2006 02:08 AM
Problem - Calendar to Inbox to Calendar moves date to current date =?Utf-8?B?amVzc2ljYQ==?= Microsoft Outlook Calendar 1 6th Jun 2005 03:05 PM
Setting selected date in ActiveX Calendar 10.0 Junkguy Microsoft Access Forms 5 20th Sep 2004 08:09 PM
Calendar Control - Problem with Selected Date Change - Have to Press Twice Michael England Microsoft ASP .NET 0 26th Nov 2003 06:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:59 AM.