Solved

Adding Appointment from Access to Outlook on Another Persons Calendar

Posted on 2008-06-24
1
405 Views
Last Modified: 2013-11-27
I am trying to get Access to put an appointment onto another person's calendar in outlook.  I have a form that you choose who you want to add the appointment to, however, when the code searches for the Mailbox for the person selected it can not find it.

Pleae note that I am relatively new to VBA for Access

The code I am using is below...most of which I have goten off this website and a few others.

Please help,

BVass
****CODE START****
 
Option Explicit
 
Dim outObj As New Outlook.Application
Dim outNS As Outlook.NameSpace
Dim outFolders As Outlook.MAPIFolder
Dim outSubFolders As Outlook.MAPIFolder
Dim outAppt As Outlook.AppointmentItem
Dim strMail, strFirst, strLast As String
Dim intCount As Integer
Dim frm As Form
 
Function addAppt()
 
' Save record first to be sure required fields are filled.
    DoCmd.RunCommand acCmdSaveRecord
' Exit the procedure if appointment has been added to Outlook.
    Set frm = Screen.ActiveForm
    
    If frm.AddedToOutlook = True Then
        MsgBox "This appointment already added to Microsoft Outlook"
        Exit Function
    Else
'Set the name of the Mailbox
        frm.Auditor.SetFocus
        strMail = frm.Auditor.Text
        intCount = InStrRev(strMail, " ")
        strFirst = Trim$(Left$(strMail, intCount))
        strLast = Trim$(Right$(strMail, intCount))
        strMail = "Mailbox - " & strLast & ", " & strFirst
        
' Add a new appointment.
        Set outNS = outObj.GetNamespace("MAPI")
        Set outFolders = outNS.Folders(strMail)
        Set outSubFolders = outFolders.Folders("Calendar")
        Set outAppt = outObj.CreateItem(olAppointmentItem)
        With outAppt
           .Start = frm.ApptDate & " " & frm.ApptTime
           .Duration = frm.ApptLength
           .Subject = frm.Appt
           If Not IsNull(frm.ApptNotes) Then .Body = frm.ApptNotes
           If Not IsNull(frm.ApptLocation) Then .Location = _
              frm.ApptLocation
           If frm.ApptReminder Then
              .ReminderMinutesBeforeStart = frm.ReminderMinutes
              .ReminderSet = True
           End If
           .Save
        End With
    End If
    ' Release the Outlook object variable.
    Set outObj = Nothing
    ' Set the AddedToOutlook flag, display a message.
    frm.AddedToOutlook = True
    DoCmd.RunCommand acCmdSaveRecord
    MsgBox "Appointment Added!"
    Exit Function
AddAppt_Err:
    MsgBox "Error " & Err.Number & vbCrLf & Err.Description
    Exit Function
 
End Function
 
****CODE END****

Open in new window

0
Comment
Question by:BVass
1 Comment
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
ID: 21862893
BVass

This Question is almost Identical.
Try the solution:
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_21809067.html

JeffCoachman
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question