Results 1 to 7 of 7

Thread: Outlook

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    120

    Outlook

    This the small code whcih checks for new email in outlook and display a message but whenever i run this app i get msg that "can't create object" althoug i have outlook installed

    plz help
    VB Code:
    1. Sub ReadEmail()
    2.     Dim oApp As Outlook.Application
    3.     Dim oNameSpace As NameSpace
    4.     Dim oFolder As MAPIFolder
    5.     Dim oMailItem As Object
    6.     Dim cFolder As MAPIFolder
    7.     Dim myItems As Items
    8.     Dim MailCounter As Integer, FolderCount As Integer
    9.     MailCounter = 0
    10.     Dim sMessage As String
    11.     Set oApp = New Outlook.Application          '<<<<<<<<<<<<------------------Error
    12.     Set oNameSpace = oApp.GetNamespace("MAPI")
    13.     Set oFolder = oNameSpace.GetDefaultFolder(olFolderInbox)
    14.     MailCounter = oFolder.UnReadItemCount
    15.    
    16.     For FolderCount = 1 To oFolder.Folders.Count
    17.     Set cFolder = oFolder.Folders(FolderCount)
    18.     For Each oMailItem In cFolder.Items
    19.     If oMailItem.UnRead = True Then
    20.     List1.AddItem oMailItem.ReceivedTime
    21.     End If
    22.     Next oMailItem
    23.     MailCounter = mailcount + cFolder.UnReadItemCount
    24.     Next
    25.     Set oMailItem = Nothing
    26.     Set oFolder = Nothing
    27.     Set mFolder = Nothing
    28.     Set oNameSpace = Nothing
    29.     Set oApp = Nothing
    30. msg:
    31.     If MailCounter = 1 Then
    32.     MsgBox "You have 1 new message"
    33.     Else
    34.     MsgBox "You have " & MailCounter & " new messages"
    35.     End If
    36.     End Sub
    Last edited by Hack; Sep 27th, 2006 at 09:54 AM. Reason: Added [vbcode] [/vbcode] tags for more clarity.

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

    Re: Outlook

    Did you set a reference to MS Outlook xx.0 Object Library?
    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
    Lively Member
    Join Date
    Jun 2005
    Posts
    120

    Re: Outlook

    Yes i set the refrence for MS Outlook 10.0

    i found one more thing that if i run outlook and then run the code it works fine but without running outlook it won't run

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Outlook

    VB Code:
    1. 'Try
    2. Set oApp = CreateObject("Outlook.Application")
    3. 'instead of
    4. Set oApp = New Outlook.Application

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

    Re: Outlook

    I can not see any issue with this line of code.

    Set oApp = New Outlook.Application

    If you were to create a new blank forject with the outlook reference and add the dimensioning line and outlook creation line it should work. If it does then either there is something else going on in your app or possibly outlook may need repair. Do you have all the latest updates for it? Did you try a Help menu > Detect and Repair?
    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

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    120

    Re: Outlook

    i have changed the code to
    Set oApp = CreateObject("Outlook.Application")
    and also done Help menu > Detect and Repair
    but Getting same error message

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    120

    Re: Outlook

    After searching sometime I have found that error “429” comes when user does not have outlook installed on the PC but this is not in my case.
    Last edited by xor83; Sep 28th, 2006 at 04:31 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
  •  



Click Here to Expand Forum to Full Width