Results 1 to 7 of 7
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,198

    sending an outlook appointment to a recipient

    Hi Guy's i am hoping to be able to send an email contact an out appointment, this is what i have so far but this does nothing!, am I going about it the wrong way ?



    Code:
    Dim objNS As Outlook.NameSpaceDim objFolder As Outlook.MAPIFolder
    Dim objRecip As Outlook.Recipient
    Dim strName As String
    Dim objAppt As Outlook.AppointmentItem
    Dim objApp As Outlook.Application
    Dim dte As Date, dte2 As Date
    
    
    On Error Resume Next
    
    
    strName = Me.txtEmailTo
    
    
    Set objNS = objApp.GetNamespace("MAPI")
    Set objRecip = objNS.CreateRecipient(strName)
    Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)
    Set objAppt = objFolder.Items.Add
    Set objAppt = objApp.CreateItem(olAppointmentItem)
    
    
    dte = Format(Now(), "hh:nn")
    dte2 = DateAdd("h", 2, dte)
    With objAppt
                .Start = Format(Now(), "ddd-dd-mmm-yyyy")
                .End = DateAdd("d", 2, Format(Now(), "ddd-dd-mmm-yyyy"))
                .Location = Me.txtPostCode
                .Subject = "Your appointment"
                .MeetingStatus = olMeeting
                .ReminderMinutesBeforeStart = 20
                .BusyStatus = olBusy
                .RequiredAttendees = "Engineer"
                .Mileage = appointmentID
                .Recipients.ResolveAll
                .Save
                .Display
                End With
    Set objApp = Nothing
    Set objNS = Nothing
    Set objFolder = Nothing
    Set objRecip = Nothing

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,840
    Are you using Option Explicit?
    Where is appointmentID declared? Did you step through the code and watch your variables?

    EDIT 1 and 2 - forgot to mention - when trouble shooting do NOT use On Error Resume Next or you'll never find out what's wrong.
    When you turn off that line you'll probably see the problem.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,198
    ahh ok Micron, thank you, will do some more testing

  4. #4
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,198
    Dim objNS As Outlook.NameSpace
    Dim objFolder As Outlook.MAPIFolder
    Dim objRecip As Outlook.Recipient
    Dim strName As String
    Dim objAppt As Outlook.AppointmentItem
    Dim objApp As Outlook.Application
    Dim dte As Date, dte2 As Date




    strName = Me.txtName

    Set objNS = objApp.GetNamespace("MAPI") Object or variable not set
    Set objRecip = objNS.CreateRecipient(strName)
    Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)
    Set objAppt = objFolder.Items.Add
    Set objAppt = objApp.CreateItem(olAppointmentItem)


    dte = Format(Now(), "hh:nn")
    dte2 = DateAdd("h", 2, dte)
    With objAppt
    .Start = Format(Now(), "ddd-dd-mmm-yyyy")
    .End = DateAdd("d", 2, Format(Now(), "ddd-dd-mmm-yyyy"))
    .Location = Me.txtPostCode
    .Subject = "Your appointment for " & Me.txtRemovalDate
    .ReminderMinutesBeforeStart = 2880
    .RequiredAttendees = "Engineer Name"
    .Mileage = appointmentID
    .Recipients.ResolveAll
    .Save
    .Display
    End With
    Set objApp = Nothing
    Set objNS = Nothing
    Set objFolder = Nothing
    Set objRecip = Nothing

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,840
    You're trying to set objNs to something that doesn't yet exist.... objApp
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,031
    Try this link. I found it via a quick Google, top of the list.

    https://docs.microsoft.com/en-us/off...m.send(method)

  7. #7
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,198
    Thank you guys, will do some testing, thanks again

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 09-10-2020, 05:57 AM
  2. Create Outlook appointment
    By NISMOJim in forum Modules
    Replies: 22
    Last Post: 02-25-2019, 01:25 AM
  3. Adding an appointment to Outlook shared calendar
    By simon123 in forum Programming
    Replies: 1
    Last Post: 08-03-2018, 11:14 AM
  4. Replies: 3
    Last Post: 09-18-2014, 07:13 AM
  5. Replies: 1
    Last Post: 03-21-2013, 11:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums