Results 1 to 12 of 12

Thread: [2005] Add Appointment To Outlook Calendar

  1. #1

    Thread Starter
    Hyperactive Member Jonny1409's Avatar
    Join Date
    Mar 2005
    Posts
    308

    [2005] Add Appointment To Outlook Calendar

    Hello,

    I want to add an appointment to the users Outlook Calendar when I pass in a date.

    To do this, I'm calling the following code :


    Code:
    Public Sub AddHolToOutlook(ByVal m_Start As Date)
    
            ' Start Outlook.
            ' If it is already running, you'll use the same instance...
            Dim OlAPP = CreateObject("Outlook.Application")
    
            ' Logon. Doesn't hurt if you are already running and logged on...
            Dim olNs
            olNs = OlAPP.GetNamespace("MAPI")
            olNs.LogOn()
    
            ' Create a new appointment.
            Dim olAppt = OlAPP.Createitem(1)
    
            ' Setup other appointment information...
            With olAppt
                .AllDayEvent = True
                .Start = m_Start
                .Subject = "Holiday"
                .ReminderSet = False
            End With
    
            ' Save Appointment...
            olAppt.Save()
    
            ' Clean Up
            olAppt = Nothing
            olNs = Nothing
            OlAPP = Nothing
    
        End Sub
    However, I get a message saying "Cannot create ActiveX component."

    I've no idea what this means, or whether my code is anywhere near correct.

    Can anyone shed any light on this please ?
    Last edited by Jonny1409; May 10th, 2007 at 11:00 AM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: [2005] Add Appointment To Outlook Calendar

    Code:
    Dim OlAPP = As Object = CreateObject("Outlook.Application")
    
    '...
    
    Dim olAppt As Object = OlAPP.CreateItem(1)
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Hyperactive Member Jonny1409's Avatar
    Join Date
    Mar 2005
    Posts
    308

    Re: [2005] Add Appointment To Outlook Calendar

    Hi RobDog888,

    Thanks for replying.

    I've tried this, but unfortunately it doesn't work.
    I still get the same error on the line :

    Code:
    Dim OlAPP As Object = CreateObject("Outlook.Application")

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: [2005] Add Appointment To Outlook Calendar

    Are you using early or late binding? (Added a reference to Outlook or not).
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Hyperactive Member Jonny1409's Avatar
    Join Date
    Mar 2005
    Posts
    308

    Re: [2005] Add Appointment To Outlook Calendar

    I've added a reference to Microsoft Outlook through the com tab if this helps?

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: [2005] Add Appointment To Outlook Calendar

    Reference to - Microsoft Outlook xx.0 Object Library? Also, added the imports declaration?


    Code:
    Option Explicit On
    Option Strict On
    
    Imports Microsoft.Office.Interop
    
    Public Class Form1
    
    	Private moApp As Outlook.Application
    
    	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    		moApp = DirectCast(CreateObject("Outlook.Application"), Outlook.Application)
    	End Sub
    
    End Class
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Hyperactive Member Jonny1409's Avatar
    Join Date
    Mar 2005
    Posts
    308

    Re: [2005] Add Appointment To Outlook Calendar

    Yeah Microsoft Outlook 11.0 Object Library.

    I hadn't had the imports statement in, but when I've added it I get a green line under it, and the message says :

    "Namespace or type specified in the imports microsoft.office.interop doesn't contain any public member or cannot be found....."

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: [2005] Add Appointment To Outlook Calendar

    Thats usually because you may have added "Microsoft Office 11.0 Object Library" instead of "Microsoft Outlook 11.0 Object Lirary"
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Hyperactive Member Jonny1409's Avatar
    Join Date
    Mar 2005
    Posts
    308

    Re: [2005] Add Appointment To Outlook Calendar

    Hi RobDog,

    Cheers for your continued help with this - I've removed the reference and added it again. (The screenshot shows the exact file)

    It actually adds 2 things to my references :

    Microsoft.Office.Core
    Outlook

    Yet the green line above still shows.
    Attached Images Attached Images  

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: [2005] Add Appointment To Outlook Calendar

    Should be "Imports Microsoft.Office.Interop" not .Core"

    If intellisense doesnt popup with .Interop then you may not have the PIAs installed. See the link in my signature for the "Primary Interop Assemblies"
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    Hyperactive Member Jonny1409's Avatar
    Join Date
    Mar 2005
    Posts
    308

    Re: [2005] Add Appointment To Outlook Calendar

    Thanks RobDog,

    I've now installed those, and checked control panel to make sure they are there. (And they are)

    I've removed the reference and added it again.
    The green line is now gone, and interop also shows in the intellisense but I still get the error when using the code you supplied.

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: [2005] Add Appointment To Outlook Calendar

    Hmm, the code from #6 doesnt work for you then maybe something else is the issue as its basic clean code that works in 2003/2005.

    Do you have all your Windows/Office Updates installed? Any AV programs? Any issues at all? Try creating a new blank solution and place my code behind a form. Test.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width