|
-
Oct 20th, 2006, 02:38 AM
#1
Thread Starter
Junior Member
[RESOLVED] Outlook Verification
Hi,
I have obtained some code to check for new emails in Micorosft Outlook.
VB Code:
Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")
Dim olfolder As Outlook.MAPIFolder
Set olfolder = olApp.GetNamespace("MAPI").GetDefaultFolder(6)
If olfolder.UnReadItemCount > 0 Then
If olfolder.UnReadItemCount = 1 Then
lblMail = "You have " & olfolder.UnReadItemCount & " New Email"
Image2.Visible = True
Else
lblMail = "You have " & olfolder.UnReadItemCount & " New Emails"
Image2.Visible = True
End If
Else
lblMail = ""
Image2.Visible = False
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
-
Oct 20th, 2006, 03:31 AM
#2
Re: Outlook Verification
Welcome to the Forums.
Use error trapping and the GetObject/CreateObject functions.
VB Code:
Option Explicit
Private Sub Command1_Click()
On Error GoTo MyError
Dim oApp As Outlook.Application
Dim oInbox As Outlook.MAPIFolder
Set oApp = GetObject(, "Outlook.Application")
If TypeName(oApp) = "Nothing" Then
Set oApp = CreateObject("Outlook.Application")
End If
Set oInbox = oApp.GetNamespace("MAPI").GetDefaultFolder(6)
'...
Exit Sub
MyError:
If Err.Number = 429 Then
Resume Next
Else
MsgBox Err.Number & " - " & Err.Description
End If
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Oct 21st, 2006, 08:25 PM
#3
Thread Starter
Junior Member
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
-
Oct 21st, 2006, 09:06 PM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Oct 22nd, 2006, 03:00 AM
#5
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Oct 22nd, 2006, 07:21 PM
#6
Thread Starter
Junior Member
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 - ) 
-
Oct 23rd, 2006, 12:52 AM
#7
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Oct 23rd, 2006, 05:52 AM
#8
Thread Starter
Junior Member
Re: Outlook Verification
Here are all the sections of code that aren't protected by copyright (apart from my own )
VB Code:
Option Explicit
Dim cpuint As Integer
Dim pagefileint As Integer
Dim diskint As Long
Dim diskintdev As Long
Dim toppos As Integer
Dim leftpos As Integer
Private Sub Form_Load()
If App.PrevInstance = True Then
End
End If
frmScreenSaver.WindowState = 2
Call PutWindowOnTop(Me)
lblHostname = "Computer Name: " & GetIPHostName() 'this checks computer settings, ip, host name
lblIpaddress = "IP Address: " & GetIPAddress() 'GetIPHostName, GetIPAddress, FindUserName (c) Randy Birch
lblUsername = "Current User: " & FindUserName
Dim olApp As Outlook.Application 'this is the start of the outlook check for new emails code
Set olApp = CreateObject("Outlook.Application")
Dim olfolder As Outlook.MAPIFolder
Set olfolder = olApp.GetNamespace("MAPI").GetDefaultFolder(6)
If olfolder.UnReadItemCount > 0 Then
If olfolder.UnReadItemCount = 1 Then
lblMail = "You have " & olfolder.UnReadItemCount & " New Email"
Image2.Visible = True
Else
lblMail = "You have " & olfolder.UnReadItemCount & " New Emails"
Image2.Visible = True
End If
Else
lblMail = ""
Image2.Visible = False
End If
Call GetWinVersion 'this calls the copyright code to determine the windows version. Windows version code (c)Randy Birch
lblWinver = " " & versionname & " " & versionno & " build " & buildno & " (" & servicepack & ")"
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
End 'ends screensaver on click
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static count As Integer
If count > 30 Then 'ends screensaver on mouse move with 30 click give or take to compensate for small movements caused by optical mice
End
Else
count = count + 1
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
End 'end on click again
End Sub
Private Sub Timer1_Timer()
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
leftpos = Int(Rnd * 13080) + 120
toppos = Int(Rnd * 9240) + 720
Image1.Left = leftpos
Image1.Top = toppos
lblHostname = "Computer Name: " & GetIPHostName()
lblIpaddress = "IP Address: " & GetIPAddress()
lblUsername = "Current User: " & FindUserName()
Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")
Dim olfolder As Outlook.MAPIFolder
Set olfolder = olApp.GetNamespace("MAPI").GetDefaultFolder(6)
If olfolder.UnReadItemCount > 0 Then
If olfolder.UnReadItemCount = 1 Then
lblMail = "You have " & olfolder.UnReadItemCount & " New Email"
Image2.Visible = True
Else
lblMail = "You have " & olfolder.UnReadItemCount & " New Emails"
Image2.Visible = True
End If
Else
lblMail = ""
Image2.Visible = False
End If
End Sub
Private Sub Timer2_Timer()
cpuint = SystemMonitor1.Counters.Item(3).Value 'timer 2 ticks every second and displays up to date system information and time
pagefileint = SystemMonitor1.Counters.Item(1).Value 'unfortunatly the SystemMonitor control does not work on some computers
diskint = SystemMonitor1.Counters.Item(2).Value
lblCPU = "CPU Usage: " & cpuint & "%"
lblPagefile = "Memory Usage: " & pagefileint & " Pages/Sec"
diskintdev = diskint / 1024
lblDisk = "Hard Disk Usage: " & diskintdev & " KBytes/Sec"
lblTime = Time
lblDate = Date
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 - ) 
-
Oct 23rd, 2006, 05:08 PM
#9
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:
Option Explicit
Dim cpuint As Integer
Dim pagefileint As Integer
Dim diskint As Long
Dim diskintdev As Long
Dim toppos As Integer
Dim leftpos As Integer
Private Sub Form_Load()
[b]On Error GoTo MyError[/b]
If App.PrevInstance = True Then
[b]Unload Me[/b] 'End
End If
frmScreenSaver.WindowState = 2
Call PutWindowOnTop(Me)
lblHostname = "Computer Name: " & GetIPHostName() 'this checks computer settings, ip, host name
lblIpaddress = "IP Address: " & GetIPAddress() 'GetIPHostName, GetIPAddress, FindUserName (c) Randy Birch
lblUsername = "Current User: " & FindUserName
Dim olApp As Outlook.Application 'this is the start of the outlook check for new emails code
' Set olApp = CreateObject("Outlook.Application")
[b]Set olApp = GetObject(, "Outlook.Application")
If TypeName(olApp) = "Nothing" Then
Set olApp = New Outlook.Application
End If[/b]
Dim olfolder As Outlook.MAPIFolder
Set olfolder = olApp.GetNamespace("MAPI").GetDefaultFolder(6)
If olfolder.UnReadItemCount > 0 Then
If olfolder.UnReadItemCount = 1 Then
lblMail = "You have " & olfolder.UnReadItemCount & " New Email"
Image2.Visible = True
Else
lblMail = "You have " & olfolder.UnReadItemCount & " New Emails"
Image2.Visible = True
End If
Else
lblMail = ""
Image2.Visible = False
End If
Call GetWinVersion 'this calls the copyright code to determine the windows version. Windows version code (c)Randy Birch
lblWinver = " " & versionname & " " & versionno & " build " & buildno & " (" & servicepack & ")"
[b]Exit Sub
MyError:
If Err.Number = 429 Then
Resume Next
Else
MsgBox Err.Number & " - " & Err.Description
End If[/b]
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Oct 24th, 2006, 03:25 AM
#10
Thread Starter
Junior Member
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 - ) 
-
Oct 24th, 2006, 11:38 AM
#11
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Oct 24th, 2006, 06:40 PM
#12
Thread Starter
Junior Member
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 - ) 
-
Oct 24th, 2006, 08:00 PM
#13
Re: Outlook Verification
Np, just change the If block of code that is bold to this...
VB Code:
If TypeName(olApp) = "Nothing" Then
'Set olApp = New Outlook.Application
MsgBox "Outlook not running", vbOkOnly + vbExclamation
Exit Sub
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Oct 25th, 2006, 05:39 AM
#14
Thread Starter
Junior Member
-
Oct 25th, 2006, 02:28 PM
#15
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|