appointment (meeting) window in Calendar

G

Guest

I'm trying to click the button in MS Access to open a window to shedule a
meeting.
But, I can open only the New message window from the Mail.
How could I open the Appointment window from the Calendar?
I'm using the following code:
Private Sub cmdMeeting_Click()
Dim bStarted As Boolean
Dim objOutlook As Object
Dim objMeeting As Object

Set objOutlook = GetObject(, "Outlook.Application")
If Err <> 0 Then
'Outlook wasn't running, start it from code
Set objOutlook = CreateObject("Outlook.Application")
bStarted = True
End If

Set objMeeting = objOutlook.CreateItem(olAppointmentItem)
With objMeeting

.Subject = "The meeting"

End With

objMeeting.Display

On Error Resume Next

If bStarted Then
'If we started Outlook from code, then close it
objOutlook.Quit
End If

Set objMeeting = Nothing
Set objOutlook = Nothing

End Sub
Thanks
 
G

Guest

You need to activate an Explorer object to open or switch to the Calendar
folder. There are also some considerations to take into account when loading
Outlook for the user to make sure it closes properly. The code below should
be structured well enough to paste right into your Access form.

Option Compare Database
Option Explicit
Dim WithEvents objMeeting As Outlook.AppointmentItem
Dim WithEvents objInsp As Outlook.Inspector
Dim bStarted As Boolean
Dim objOutlook As Outlook.Application
Dim objExp As Outlook.Explorer
Dim objNS As Outlook.NameSpace

Private Sub cmdMeeting_Click()
On Error Resume Next

Set objOutlook = GetObject(, "Outlook.Application")

If Err.Number <> 0 Then
'Outlook wasn't running, start it from code
Set objOutlook = New Outlook.Application
'Activate the default Calendar folder
Set objNS = objOutlook.GetNamespace("MAPI")
Set objExp =
objOutlook.Explorers.Add(objNS.GetDefaultFolder(olFolderCalendar),
olFolderDisplayNormal)
objExp.Activate
bStarted = True
Else
Set objNS = objOutlook.GetNamespace("MAPI")
Set objExp = objOutlook.ActiveExplorer
objExp.SelectFolder objNS.GetDefaultFolder(olFolderCalendar)
End If

Set objMeeting = objOutlook.CreateItem(olAppointmentItem)
With objMeeting
.Subject = "The meeting"
End With

Set objInsp = objMeeting.GetInspector
Set objMeeting = Nothing
objInsp.Display
End Sub

Private Sub objInsp_Close()
If bStarted Then
'If we started Outlook from code, then close it
objExp.Close
objNS.Logoff
objOutlook.Quit
End If

Set objInsp = Nothing
Set objExp = Nothing
Set objNS = Nothing
Set objOutlook = Nothing
bStarted = False 'Reset for debugging
End Sub
 
G

Guest

Thanks a lot, Eric.
How could I implement your code below thru the late binding (Dim .. As
Object) to avoid the problems with references?
Set objNS = objOutlook.GetNamespace("MAPI")
Set objExp =
objOutlook.Explorers.Add(objNS.GetDefaultFolder(olFolderCalendar),
olFolderDisplayNormal)
objExp.Activate
bStarted = True
Else
Set objNS = objOutlook.GetNamespace("MAPI")
Set objExp = objOutlook.ActiveExplorer
objExp.SelectFolder objNS.GetDefaultFolder(olFolderCalendar)
 
D

David C. Holley

What about the Outlook View(name?) ActiveX Control? I've never actually
used it, but in reading up on it sounds promising.
 
G

Guest

The Outlook View Control is very cool, but it doesn't really apply to this
situation. The OVC requires a container like a custom Outlook form/User
Form/Windows Form, or a web page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top