close reminder window programatically

  • Thread starter Thread starter soworl
  • Start date Start date
S

soworl

Hi All,

I cannot find the way that close reminder window programatically.

I found dismiss method here.
http://msdn2.microsoft.com/en-us/library/bb176766.aspx
But I cannot find close method...

basically, I want these,
1> call sql query at once reminder fire -> done
2> change the label of item -> done
3> close reminder window

Please, advice me!

Thanks,
soworl
 
There's no method of closing the window when it's opened. You can intercept
the event when a reminder fires and prevent the window from opening in the
first place. Once it's opened you would have to use FindWindow() or some
other Win32 API calls to get the window handle for the Reminders window and
then send it a WM_CLOSE message, again using Win32 API calls.
 
Thanks Ken,

Can you give me a useful link for intercept the event & prevent open
reminder window?

for your info, Here is my code
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim WithEvents myolapp As Outlook.Application

Private Sub Application_Startup()
Initialize_handler
End Sub

Sub Initialize_handler()
Set myolapp = Outlook.Application
End Sub

Private Sub myolapp_Reminder(ByVal Item As Object)
Interval = DateDiff("s", Now(), Item.End) 'seconds
EnableTimer Interval * 1000, Me 'first parameter=milliseconds
' I'll add sql query here
SetApptColorLabel Item, 5
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Thanks,
soworl
 
The Application.Reminder() event can't be cancelled, so it's good for
telling you that a reminder has fired only, not for preventing the Reminders
window from appearing. For that you want to use the Application.Reminders
collection and to handle the BeforeReminderShow(Cancel As Boolean) event. If
Cancel is set to True in that event the window won't open. Then you can
handle the Reminders.ReminderFire() event to see what reminder is firing or
use the Application.Reminder event to see that.
 
thanks for your help.

I modified my source for test, but it's not working.
I cannot see the msg box, "Do you want to view the reminder"

do you know what's wrong?

Thanks,
sowor
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim WithEvents myolapp As Outlook.Application
Dim WithEvents colReminders As Reminders

Private Sub Application_Startup()
Initialize_handler
End Sub

Sub Initialize_handler()
Set myolapp = Outlook.Application
Set colReminders = myolapp.Reminders
End Sub

Private Sub myolapp_Reminder(ByVal Item As Object)
Interval = DateDiff("s", Now(), Item.End) 'seconds
EnableTimer Interval * 1000, Me 'first parameter=milliseconds
SetApptColorLabel Item, 5
End Sub

Private Sub colReminders_BeforeReminderShow(Cancel As Boolean)
Dim lngAns As Long

lngAns = MsgBox("Do you want to view the reminder?", vbYesNo)
If lngAns = vbYes Then
Cancel = False
Else
Cancel = True
End If
End Su
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
Are any macros working? What happens if you put the cursor in
Application_Startup() and press F5, does the code run and then initialize
the event handlers?

The code is in ThisOutlookSession?
 
so rear..

the code is in thisOutlookSession.
it used to call myolapp_Reminder, but not now.
 
Are any macros working?

What happens if you put the cursor in Application_Startup() and press F5,
does the code run and then initialize the event handlers?

What are your macro security settings (Tools, Macros, Security)?
 
security settings : medium
What happens if you put the cursor in Application_Startup() and press F5,
-> nothing T.T

when i run the outlook, it asks whether enable macro or not.
I click enable macro.
 
Show the exact code you're currently using.

So if you press F5 in that Application_Startup() code it runs and without
any errors?
 
Hi,

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Application_Startup()
Initialize_handler
End Sub

Private Sub Application_Quit()
DisableTime
End Sub

Public Sub Initialize_handler()
msgBox "Hi1"
End Sub

Private Sub Application_Reminder(ByVal Item As Object)
msgBox "Hi2"
Interval = DateDiff("s", Now(), Item.End) 'seconds
EnableTimer Interval * 1000, Me 'first parameter=milliseconds
SetApptColorLabel Item, 7
End Su
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
I fixed some code.
Now, Above code is running code. it works fine. I can get msg box, "Hi1" and
"H2".
but I don't know how can I put below sub.
I tested "Application_BeforeReminderShow" and "Reminders_BeforeReminderShow".
Neither can catch BeforeReminderShow.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Reminders_BeforeReminderShow(Cancel As Boolean)
Dim lngAns As Long

lngAns = MsgBox("Do you want to view the reminder?", vbYesNo)
If lngAns = vbYes Then
Cancel = False
Else
Cancel = True
End If
End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
If you look in the Object Browser you will see that there is no
Application_BeforeReminderShow() event, which is a good reason that you
can't trap that event.

Add this to the module level declarations:

Private WithEvents colReminders As Outlook.Reminders

Add this to Initialize_handler():

Set colReminders = Application.Reminders

Then an event handler like this should fire before the reminder window is
displayed:

Private Sub colReminders_BeforeReminderShow(Cancel As Boolean)
 
thanks for your quick help.

I chaged some code, and it works fine.
now I have another problem which is getting Item object in the
BeforeReminderShow.
When I use Application_Reminder, I can get the Appointment item object, so I
changed label and use Item.end time.
But in case of BeforeReminderShow, how can I get the item object.

here is my code.
I made class modules for solve previous problems.
'''''''''''''''''''''''''''ThisOutlookSession'''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim ReminderClass As New Class1
Private Sub Application_Startup()
ReminderClass.init
End Sub
Private Sub Application_Quit()
DisableTimer
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''Class1''''''''''''''''''''''''''''''''''''''''''
Private WithEvents myolapp As Outlook.Application
Private WithEvents colReminders As Reminders
Sub Class_Terminate()
Call DeRefExplorers
End Sub
Public Sub init()
Set myolapp = Outlook.Application
Set colReminders = myolapp.Reminders
End Sub
Public Sub DeRefExplorers()
Set myolapp = Nothing
Set colReminders = Nothing
End Sub
Private Sub colReminders_BeforeReminderShow(Cancel As Boolean)
Dim lngAns As Long

lngAns = MsgBox("Do you want to view the reminder?", vbYesNo)
If lngAns = vbYes Then
Cancel = False
Else
Cancel = True
End If

End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''module1''''''''''''''''''''''''''''''''''''''''''
' <Modul: modTimer.bas>
Private Declare Function SetTimer Lib "user32.dll" (ByVal hwnd As Long,
ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As
Long
Private Declare Function KillTimer Lib "user32.dll" (ByVal hwnd As Long,
ByVal nIDEvent As Long) As Long

Const WM_TIMER = &H113

Private hEvent As Long
Private m_oCallback As Object

Public Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As
Long, ByVal lParam As Long)
If uMsg = WM_TIMER Then
m_oCallback.Timer
End If
End Sub

Public Function EnableTimer(ByVal msInterval As Long, oCallback As Object)
As Boolean
If hEvent <> 0 Then
Exit Function
End If
hEvent = SetTimer(0&, 0&, msInterval, AddressOf TimerProc)
Set m_oCallback = oCallback
EnableTimer = CBool(hEvent)
End Function

Public Function DisableTimer()
If hEvent = 0 Then
Exit Function
End If
KillTimer 0&, hEvent
hEvent = 0
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
As I mentioned originally, way back in this thread ,you will need to handle
an additional event to get the reminder that is actually firing. You can try
using Application_Reminder() or Reminders.ReminderFire() and see which best
meets your needs.
 
Hi,

I found way to get Appointment item object, see below code.
but I get another problem - -;
Even I set objItem.ReminderSet = False, it is called multiple.
I want to call doSomething just one time.

Thanks for your help.
sowor
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub colReminders_BeforeReminderShow(Cancel As Boolean)
Cancel = True
doSomething
End Sub

Public Sub doSomething()
Dim objRem As Reminder
Dim objItem As Object

If colReminders.Count <> 0 Then
For Each objRem In colReminders
Set objItem = objRem.Item
msgBox objItem.End
SetApptColorLabel objItem, 4
objItem.ReminderSet = False
Next
Else
MsgBox "There are no reminders in the collection."
End If
Set objItem = Nothing
Set objRem = Nothing
End Su
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
If you are setting ReminderSet = False then you are effectively removing
that item from the Reminders collection. Never use a For...Each loop or up
counting For loop when removing items from a collection in any way (move,
delete, change a property that removes it), use a down counting For loop.

I'm not sure what you mean about calling doSomething() more than once, it
should be called once for each time your event handler fires.
 
Hi,

so strange...

I tested several ways.
1> objItem.ReminderSet = False -> no error but reminder still fires
2> objRem.Dismiss -> error occures, Run-time error'5' Invalid procudure
call or arguement

If I don't do anything with objRem( doSomething2), it calls only one.
but I need to do something with appointment object (below objRem.Item)

Is there any way?
Please, advice me.

Thanks,
soworl

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub colReminders_BeforeReminderShow(Cancel As Boolean)
MsgBox "start beforeReminderShow"
Cancel = True
doSomething2
End Sub

Public Sub doSomething2()
MsgBox "doSomething2!"
End Sub

Public Sub doSomething()
Dim objRem As Reminder
Dim objItem As Object

MsgBox colReminders.Count

If colReminders.Count <> 0 Then
For i = 1 To colReminders.Count
Set objRem = colReminders(i)
Set objItem = objRem.Item
SetApptColorLabel objItem, 5
objItem.ReminderSet = False
' objRem.Dismiss
MsgBox "did it"
Next
Else
MsgBox "There are no reminders in the collection."
End If
Set objItem = Nothing
Set objRem = Nothing
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
Use either Reminder.Dismiss or set ReminderSet = False, don't do both. If
you set ReminderSet = False that removes the reminder from the collection
and therefore Dismiss would cause an error.

Also, I mentioned to use a count down For loop, not a count up one:

For i = colReminders.Count To 1 Step -1
 
I tested either Reminder.Dismiss(2) or set ReminderSet(1) = False.
I didn't do both.

I changed, For i = colReminders.Count To 1 Step -1.
but still same happens. (it call beforeReminderShow multiple)

I'm thinking that after cancel=true, if I use colReminders, it activate that
reminder again?

so strange.
 
I don't know you'd have to experiment with stepping the code and judicious
use of logging or debug.print statements. When I've intercepted the
reminders dialog to suppress it from displaying I've never played with
actually dismissing the reminders or setting ReminderSet = False, I just use
those reminders in my own dialogs.
 
Back
Top