Results 1 to 15 of 15

Thread: [RESOLVED] Outlook Verification

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2006
    Posts
    30

    Resolved [RESOLVED] Outlook Verification

    Hi,

    I have obtained some code to check for new emails in Micorosft Outlook.
    VB Code:
    1. Dim olApp As Outlook.Application
    2.    Set olApp = CreateObject("Outlook.Application")
    3.    Dim olfolder As Outlook.MAPIFolder
    4.    
    5. Set olfolder = olApp.GetNamespace("MAPI").GetDefaultFolder(6)
    6. If olfolder.UnReadItemCount > 0 Then
    7. If olfolder.UnReadItemCount = 1 Then
    8. lblMail = "You have " & olfolder.UnReadItemCount & " New Email"
    9. Image2.Visible = True
    10. Else
    11. lblMail = "You have " & olfolder.UnReadItemCount & " New Emails"
    12. Image2.Visible = True
    13. End If
    14. Else
    15. lblMail = ""
    16. Image2.Visible = False
    17. End If

    What I want to know is how can I make the program test to see whether Outlook is open or not becuase it is really annoying if you don't have it open and the program is attempting to check for new emails every minute and is startiing outlook automatically and slowing down your system.

    Thanks

  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 Verification

    Welcome to the Forums.

    Use error trapping and the GetObject/CreateObject functions.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.     On Error GoTo MyError
    5.     Dim oApp As Outlook.Application
    6.     Dim oInbox As Outlook.MAPIFolder
    7.    
    8.     Set oApp = GetObject(, "Outlook.Application")
    9.     If TypeName(oApp) = "Nothing" Then
    10.         Set oApp = CreateObject("Outlook.Application")
    11.     End If
    12.     Set oInbox = oApp.GetNamespace("MAPI").GetDefaultFolder(6)
    13.     '...
    14.     Exit Sub
    15. MyError:
    16.     If Err.Number = 429 Then
    17.         Resume Next
    18.     Else
    19.         MsgBox Err.Number & " - " & Err.Description
    20.     End If
    21. End Sub
    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
    Junior Member
    Join Date
    Oct 2006
    Posts
    30

    Unhappy Re: Outlook Verification

    Thanks, glad I found it.
    ...Unfortunatly that didn't work. It isn't really an error as the OLE starting the program to be able to access it if it isn't already open. What I need is a bit of code to check whether outlook.exe is running and if it isn't then completly skip that portion of code. If it is running however it will check the inbox for new emails. Well....at least i need something of that effect.

    Thanks

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

    Re: Outlook Verification

    This does work but since your using an OLE control object which you didnt state you should still be able to trapp the error regardless.

    Post you code so i can see whats wrong.
    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
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Outlook Verification

    We have code similar to Randy's but I'm sorry that I will have to delete the posts as its a copyright violation to be posting any of his code on any website or such as noted in his copyright code comments.

    ... , but you may not reproduce
    ' or publish this code on any web site,
    Actually I have some code posted to duplicate network neighborhood too.


    No worries though. Sometimes its not easy explaining situations or on the other side, providing help.
    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
    Junior Member
    Join Date
    Oct 2006
    Posts
    30

    Re: Outlook Verification

    So can you help me?
    OHYEAH_456
    The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
    Nathaniel Borenstein (1957 - )

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

    Re: Outlook Verification

    Yes, if you post what you have so far.
    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

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Oct 2006
    Posts
    30

    Post Re: Outlook Verification

    Here are all the sections of code that aren't protected by copyright (apart from my own )

    VB Code:
    1. Option Explicit
    2. Dim cpuint As Integer
    3. Dim pagefileint As Integer
    4. Dim diskint As Long
    5. Dim diskintdev As Long
    6. Dim toppos As Integer
    7. Dim leftpos As Integer
    8.  
    9. Private Sub Form_Load()
    10. If App.PrevInstance = True Then
    11. End
    12. End If
    13. frmScreenSaver.WindowState = 2
    14. Call PutWindowOnTop(Me)
    15. lblHostname = "Computer Name: " & GetIPHostName() 'this checks computer settings, ip, host name
    16. lblIpaddress = "IP Address: " & GetIPAddress() 'GetIPHostName, GetIPAddress, FindUserName (c) Randy Birch
    17. lblUsername = "Current User: " & FindUserName
    18.    Dim olApp As Outlook.Application 'this is the start of the outlook check for new emails code
    19.    Set olApp = CreateObject("Outlook.Application")
    20.    Dim olfolder As Outlook.MAPIFolder
    21.    
    22. Set olfolder = olApp.GetNamespace("MAPI").GetDefaultFolder(6)
    23. If olfolder.UnReadItemCount > 0 Then
    24. If olfolder.UnReadItemCount = 1 Then
    25. lblMail = "You have " & olfolder.UnReadItemCount & " New Email"
    26. Image2.Visible = True
    27. Else
    28. lblMail = "You have " & olfolder.UnReadItemCount & " New Emails"
    29. Image2.Visible = True
    30. End If
    31. Else
    32. lblMail = ""
    33. Image2.Visible = False
    34. End If
    35. Call GetWinVersion 'this calls the copyright code to determine the windows version. Windows version code (c)Randy Birch
    36. lblWinver = "  " & versionname & " " & versionno & " build " & buildno & " (" & servicepack & ")"
    37. End Sub
    38.  
    39. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    40. End 'ends screensaver on click
    41. End Sub
    42.  
    43. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    44. Static count As Integer
    45. If count > 30 Then 'ends screensaver on mouse move with 30 click give or take to compensate for small movements caused by optical mice
    46. End
    47. Else
    48. count = count + 1
    49. End If
    50.  
    51. End Sub
    52.  
    53. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    54. End 'end on click again
    55. End Sub
    56.  
    57. Private Sub Timer1_Timer()
    58. Randomize 'timer 1 ticks every 10 seconds and moves image around screen as well as refreshing infrequent changing information such as ip address and new emails
    59. leftpos = Int(Rnd * 13080) + 120
    60. toppos = Int(Rnd * 9240) + 720
    61. Image1.Left = leftpos
    62. Image1.Top = toppos
    63. lblHostname = "Computer Name: " & GetIPHostName()
    64. lblIpaddress = "IP Address: " & GetIPAddress()
    65. lblUsername = "Current User: " & FindUserName()
    66.    Dim olApp As Outlook.Application
    67.    Set olApp = CreateObject("Outlook.Application")
    68.    Dim olfolder As Outlook.MAPIFolder
    69.    
    70. Set olfolder = olApp.GetNamespace("MAPI").GetDefaultFolder(6)
    71. If olfolder.UnReadItemCount > 0 Then
    72. If olfolder.UnReadItemCount = 1 Then
    73. lblMail = "You have " & olfolder.UnReadItemCount & " New Email"
    74. Image2.Visible = True
    75. Else
    76. lblMail = "You have " & olfolder.UnReadItemCount & " New Emails"
    77. Image2.Visible = True
    78. End If
    79. Else
    80. lblMail = ""
    81. Image2.Visible = False
    82. End If
    83. End Sub
    84.  
    85. Private Sub Timer2_Timer()
    86. cpuint = SystemMonitor1.Counters.Item(3).Value 'timer 2 ticks every second and displays up to date system information and time
    87. pagefileint = SystemMonitor1.Counters.Item(1).Value 'unfortunatly the SystemMonitor control does not work on some computers
    88. diskint = SystemMonitor1.Counters.Item(2).Value
    89. lblCPU = "CPU Usage: " & cpuint & "%"
    90. lblPagefile = "Memory Usage: " & pagefileint & " Pages/Sec"
    91. diskintdev = diskint / 1024
    92. lblDisk = "Hard Disk Usage: " & diskintdev & " KBytes/Sec"
    93. lblTime = Time
    94. lblDate = Date
    95. End Sub

    Randy Birch is my hero, without him most of the main features of this program would not work
    THANKS RANDY
    Last edited by oh_yeah456; Oct 23rd, 2006 at 05:57 AM. Reason: forgot some notes
    OHYEAH_456
    The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
    Nathaniel Borenstein (1957 - )

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

    Re: Outlook Verification

    You shouldnt ever need to use "End" in VB programming. It is bad and can lead to orphaned resource usage, corrupted database, etc.

    I'll get you started, we will add error handling and the outlook test code.


    I see you have a reference to MS Outlook xx.0 Object Library so we might as well take advantage of that. So we will use Early Binding.


    VB Code:
    1. Option Explicit
    2.  
    3. Dim cpuint As Integer
    4. Dim pagefileint As Integer
    5. Dim diskint As Long
    6. Dim diskintdev As Long
    7. Dim toppos As Integer
    8. Dim leftpos As Integer
    9.  
    10. Private Sub Form_Load()
    11.     [b]On Error GoTo MyError[/b]
    12.     If App.PrevInstance = True Then
    13.         [b]Unload Me[/b] 'End
    14.     End If
    15.     frmScreenSaver.WindowState = 2
    16.     Call PutWindowOnTop(Me)
    17.     lblHostname = "Computer Name: " & GetIPHostName() 'this checks computer settings, ip, host name
    18.     lblIpaddress = "IP Address: " & GetIPAddress() 'GetIPHostName, GetIPAddress, FindUserName (c) Randy Birch
    19.     lblUsername = "Current User: " & FindUserName
    20.    
    21.     Dim olApp As Outlook.Application 'this is the start of the outlook check for new emails code
    22. '   Set olApp = CreateObject("Outlook.Application")
    23.     [b]Set olApp = GetObject(, "Outlook.Application")
    24.     If TypeName(olApp) = "Nothing" Then
    25.         Set olApp = New Outlook.Application
    26.     End If[/b]
    27.     Dim olfolder As Outlook.MAPIFolder
    28.    
    29.     Set olfolder = olApp.GetNamespace("MAPI").GetDefaultFolder(6)
    30.     If olfolder.UnReadItemCount > 0 Then
    31.         If olfolder.UnReadItemCount = 1 Then
    32.             lblMail = "You have " & olfolder.UnReadItemCount & " New Email"
    33.             Image2.Visible = True
    34.         Else
    35.             lblMail = "You have " & olfolder.UnReadItemCount & " New Emails"
    36.             Image2.Visible = True
    37.         End If
    38.     Else
    39.         lblMail = ""
    40.         Image2.Visible = False
    41.     End If
    42.     Call GetWinVersion 'this calls the copyright code to determine the windows version. Windows version code (c)Randy Birch
    43.     lblWinver = "  " & versionname & " " & versionno & " build " & buildno & " (" & servicepack & ")"
    44.     [b]Exit Sub
    45. MyError:
    46.     If Err.Number = 429 Then
    47.         Resume Next
    48.     Else
    49.         MsgBox Err.Number & " - " & Err.Description
    50.     End If[/b]
    51. End Sub
    Last edited by RobDog888; Oct 23rd, 2006 at 05:12 PM.
    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

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Oct 2006
    Posts
    30

    Re: Outlook Verification

    Nope, still didn't stop outlook from starting automatically. It starts and then closes again almost instantly (once it has checked for new emails). It does this every time it refreshes and lets face it, outlook isn't the lightest program on system resources

    Is error 429 some sort of "outlook not running" code? The program doesn't stop because of an error, it just starts outlook, checks, closes it and keeps going.

    Any more ideas?

    Thanks,
    Last edited by oh_yeah456; Oct 24th, 2006 at 03:27 AM. Reason: my smiley faces didnt work :(
    OHYEAH_456
    The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
    Nathaniel Borenstein (1957 - )

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

    Re: Outlook Verification

    Well that is a different issue as I thought it was just checking if Oputlook is running or not and if its running attach to that instance and if its not running then create a new instance.?

    429 is a "Cant create Object" error which applies to allot of objects.
    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

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Oct 2006
    Posts
    30

    Re: Outlook Verification

    OK. All I want it to do basically is detect whether OUTLOOK.EXE is running in the memory and then if not it skips the email checking code to keep the computer running efficiently. Also, if someone doesn't use outlook they may be faced with a "Set Up Email Accounts" dialouge out of nowhere and that would confuse things.

    Gee, it is diffucult trying to convey VB problems over forums. Thanks for being patient

    Thanks
    OHYEAH_456
    The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
    Nathaniel Borenstein (1957 - )

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

    Re: Outlook Verification

    Np, just change the If block of code that is bold to this...


    VB Code:
    1. If TypeName(olApp) = "Nothing" Then
    2.     'Set olApp = New Outlook.Application
    3.     MsgBox "Outlook not running", vbOkOnly + vbExclamation
    4.     Exit Sub
    5. End If
    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

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Oct 2006
    Posts
    30

    Thumbs up Re: Outlook Verification

    Oh thats good. That works perfectly!
    Thanks very much
    You're awsome

    Last edited by oh_yeah456; Oct 25th, 2006 at 05:43 AM. Reason: Would you believe I miss-spelt you're!
    OHYEAH_456
    The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
    Nathaniel Borenstein (1957 - )

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

    Re: Outlook Verification

    Your Welcome.

    Ps, dont forget to Resolve your thread.
    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