UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
3 Pages V  1 2 3 >  (Go to first unread post)
   Reply to this topicStart new topic
> Outlook Freezes With Macro, Any Version    
 
   
dflak
post Sep 28 2018, 12:21 PM
Post#1


Utter Access VIP
Posts: 6,286
Joined: 22-June 04
From: North Carolina


Actual version 2016 with Exchange Server.

I borrowed the following code from online and made some modifications to it. It "monitors" various mailboxes every 15 minutes and mails me a message with the number of items in each mailbox. I have to work with reports and I have to wait until they are all in before I can work with them. This program is my watchdog.

It works perfectly. Every now and then (like once every other day), I will see an error message come up trapped by the ErrorExit function and the mail goes on without issue. However, about once a day, as I am composing a reply to an email, Outlook Freezes. I move the cursor over it and it disappears. I have to kill it with the Windows Task Manager. Under normal conditions. Outlook gobbles up less than a tenth of a percent of the CPU. However, when it freezes, it is using 24% of the CPU. This leads me to believe that there is something in the code that is causing this. I would like to escape it like I do with errors so Outlook doesn't stop. I don't care if it has to suspend the macro and close it and wait until the next time around.

I do not get any error messages from Outlook and it does not crash. It just stops working. Here is the code
CODE
Option Explicit

Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerfunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long

Public TimerID As Long 'Need a timer ID to eventually turn off the timer. If the timer ID <> 0 then the timer is running

Public Sub ActivateTimer(ByVal nMinutes As Long)
  nMinutes = nMinutes * 1000 * 60 'The SetTimer call accepts milliseconds, so convert to minutes
  If TimerID <> 0 Then Call DeactivateTimer 'Check to see if timer is running before call to SetTimer
  TimerID = SetTimer(0, 0, nMinutes, AddressOf TriggerTimer)
  If TimerID = 0 Then
    MsgBox "The timer failed to activate."
  End If
End Sub

Public Sub DeactivateTimer()
Dim lSuccess As Long
  lSuccess = KillTimer(0, TimerID)
  If lSuccess = 0 Then
    MsgBox "The timer failed to deactivate."
  Else
    TimerID = 0
  End If
End Sub

Public Sub TriggerTimer(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idevent As Long, ByVal Systime As Long)
  ' MsgBox "The TriggerTimer function has been automatically called!"
  ' Place VB Code Here
  Call MailAlert
End Sub

Sub MailAlert()
Dim olApp As Object                     ' Outlook Application
Dim olNS As Object                      ' Outlook Name Space
Dim FldrIn As Object                    ' Dock Schedule folder
Dim FldrOut As Object                   ' Dock Schedule processed folder

Dim olAtt As Object                     ' Outlook attachement
Dim MailBox As String                   ' Labor Analysis mailbox
Dim MailFolders() As String             ' Array of mail folders
Dim FolderNum As Long                   ' Folder number
Dim InFolder As String                  ' Mail folder to check

'Dim shL As Worksheet                    ' Mail message
Dim cl As String                         ' Generic Pointer
Dim MailBody As String                  ' Mail Body
Const olMailItem As Long = 0

On Error GoTo ErrorExit

' Initalize variables
MailBox = "Labor Analysis"
MailBody = ""
MailFolders = Split("Amazon Daily Ops Reports,Amazon Dock Master Data,Amazon Forecast,Amazon Primary Volume Drivers,Cube Reports,Lulus,Pepsi Ops Rpt", ",")


' Set up mailbox
Set olApp = CreateObject("Outlook.Application")
Set olNS = olApp.GetNamespace("MAPI")

For FolderNum = 0 To UBound(MailFolders)
    InFolder = MailFolders(FolderNum)
    Set FldrIn = olNS.Folders(MailBox).Folders("Inbox").Folders(InFolder)
    DoEvents
    If FldrIn.Items.Count > 0 Then
        MailBody = MailBody & "Folder " & InFolder & " has " & FldrIn.Items.Count & " items." & Chr(10)
    End If
Next FolderNum

' Clean up Outlook
Set FldrIn = Nothing
Set olNS = Nothing
Set olApp = Nothing

If MailBody <> "" Then
    ' Mail the message
    Mail_Workbook "mymail@mydomain", "Data Mail Alert!", MailBody
End If

Exit Sub

ErrorExit:
MsgBox Err.Number & Chr(10) & Err.Description, vbOKOnly, "An error has occurred."
End Sub


The Mail_Workbook code follows. I use this code in other applications (from Excel) and it does not have an issue
CODE
Sub Mail_Workbook(ToString As String, SubjectString As String, BodyString As String, _
    Optional CCString As String, Optional BCCString As String, Optional AttachmentName As String)
    Dim OutApp As Object
    Dim OutMail As Object

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
   ' Change the mail address and subject in the macro before you run it.
    With OutMail
        .To = ToString
        If CCString <> "" Then
            .CC = CCString
        End If
        If BCCString <> "" Then
            .BCC = BCCString
        End If
        .Subject = SubjectString
        .Body = BodyString
        If AttachmentName <> "" Then
            .Attachments.Add (AttachmentName)
        End If
        
        ' Add special to paste table
        '.HTMLBody = RangetoHTML(Sheets("Body Picture").Range("$A$1:$N$2"))
        
        .Send
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

--------------------
Dan

One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.
Please zip and attach samples. It makes life easier for those who have to figure out what you are trying to do. Thanks
Go to the top of the page
 
ADezii
post Sep 29 2018, 09:11 AM
Post#2



Posts: 2,690
Joined: 4-February 07
From: USA, Florida, Delray Beach


Have you considered creating a Single, Global Instance of Outlook instead of creating the Instance each time that MailAlert() is being executed? What I am getting at is perhaps several of these individual Instances are somehow not being destroyed and accumulating System Resources. I do realize, however, that this is a long shot! laugh.gif
Go to the top of the page
 
dflak
post Oct 1 2018, 07:36 AM
Post#3


Utter Access VIP
Posts: 6,286
Joined: 22-June 04
From: North Carolina


So what you are saying is eliminate this part of the code?
CODE
' Set up mailbox
Set olApp = CreateObject("Outlook.Application")
Set olNS = olApp.GetNamespace("MAPI")


and

CODE
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)


I'll give that a try after the Monday rush.

--------------------
Dan

One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.
Please zip and attach samples. It makes life easier for those who have to figure out what you are trying to do. Thanks
Go to the top of the page
 
dflak
post Oct 1 2018, 09:20 AM
Post#4


Utter Access VIP
Posts: 6,286
Joined: 22-June 04
From: North Carolina


I gave it a shot:

If I comment out the lines in the Mail Alert part, I get an error message.

If I comment out the lines in the Mailer part, I can step through the code and everything seems to be OK except it doesn't actually mail the message.

I agree with you. I am running this from Outlook. One would think that I could take care of everything within the same instance of outlook.

At least I am closing one instance of Outlook before opening the second.

I found this code and have just enough wit to be able to modify it and blend it in with some mailer code I have from Excel. I am not too comfortable with it.

--------------------
Dan

One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.
Please zip and attach samples. It makes life easier for those who have to figure out what you are trying to do. Thanks
Go to the top of the page
 
JonSmith
post Oct 1 2018, 09:40 AM
Post#5


UtterAccess VIP
Posts: 4,053
Joined: 19-October 10



QUOTE
I agree with you. I am running this from Outlook. One would think that I could take care of everything within the same instance of outlook.


Lol. That makes your code soooo weird then as you are using late binding tongue.gif


Ok, this is starting to make sense as to why Outlook is freezing. I guess that Outlook is opening a second hidden instance of itself and then doing work there, at some point the code hits a dialog that halts the VBA and requires the user to respond before proceeding, this is possibly to do with the email you are currently writing? Maybe an alert for saving drafts or something.

Start by not opening a new instance as ADezii suggests.
Its not as simple as removing those declarations.
Only remove the ones referring to the Outlook.Application and try replacing them with ThisOutlookSession.Application

This will make the code run in the instance you are running it in.
Go to the top of the page
 
dflak
post Oct 1 2018, 10:05 AM
Post#6


Utter Access VIP
Posts: 6,286
Joined: 22-June 04
From: North Carolina


OK, I am not comfortable with VBA code in Outlook. I commented out those lines I thought opened new instances of Excel and they yielded the results mentioned in my previous post. Obviously, I don't know what I am doing. Can I get some help? Here is what I commented out.


Edit: apparently color tags don't work between the code brackets look for the asterisks

CODE
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerfunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long

Public TimerID As Long 'Need a timer ID to eventually turn off the timer. If the timer ID <> 0 then the timer is running

Public Sub ActivateTimer(ByVal nMinutes As Long)
  nMinutes = nMinutes * 1000 * 60 'The SetTimer call accepts milliseconds, so convert to minutes
  If TimerID <> 0 Then Call DeactivateTimer 'Check to see if timer is running before call to SetTimer
  TimerID = SetTimer(0, 0, nMinutes, AddressOf TriggerTimer)
  If TimerID = 0 Then
    MsgBox "The timer failed to activate."
  End If
End Sub

Public Sub DeactivateTimer()
Dim lSuccess As Long
  lSuccess = KillTimer(0, TimerID)
  If lSuccess = 0 Then
    MsgBox "The timer failed to deactivate."
  Else
    TimerID = 0
  End If
End Sub

Public Sub TriggerTimer(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idevent As Long, ByVal Systime As Long)
  ' MsgBox "The TriggerTimer function has been automatically called!"
  ' Place VB Code Here
  Call MailAlert
End Sub

Sub MailAlert()
Dim olApp As Object                     ' Outlook Application
Dim olNS As Object                      ' Outlook Name Space
Dim FldrIn As Object                    ' Dock Schedule folder
Dim FldrOut As Object                   ' Dock Schedule processed folder

Dim olAtt As Object                     ' Outlook attachement
Dim MailBox As String                   ' Labor Analysis mailbox
Dim MailFolders() As String             ' Array of mail folders
Dim FolderNum As Long                   ' Folder number
Dim InFolder As String                  ' Mail folder to check

'Dim shL As Worksheet                    ' Mail message
Dim cl As String                         ' Generic Pointer
Dim MailBody As String                  ' Mail Body
Const olMailItem As Long = 0

'On Error GoTo ErrorExit

' Initalize variables
MailBox = "Labor Analysis"
MailBody = ""
MailFolders = Split("Amazon Daily Ops Reports,Amazon Dock Master Data,Amazon Forecast,Amazon Primary Volume Drivers,Cube Reports,Lulus,Pepsi Ops Rpt", ",")


' Set up mailbox
**************** Set olApp = CreateObject("Outlook.Application")
**************** Set olNS = olApp.GetNamespace

For FolderNum = 0 To UBound(MailFolders)
    InFolder = MailFolders(FolderNum)
    Set FldrIn = olNS.Folders(MailBox).Folders("Inbox").Folders(InFolder)
    DoEvents
    If FldrIn.Items.Count > 0 Then
        MailBody = MailBody & "Folder " & InFolder & " has " & FldrIn.Items.Count & " items." & Chr(10)
    End If
Next FolderNum

' Clean up Outlook
Set FldrIn = Nothing
Set olNS = Nothing
Set olApp = Nothing

If MailBody <> "" Then
    ' Mail the message
    Mail_Workbook "daniel.flak@xpo.com", "Data Mail Alert!", MailBody
End If

Exit Sub

ErrorExit:
MsgBox Err.Number & Chr(10) & Err.Description, vbOKOnly, "An error has occurred."
End Sub


and

CODE
Sub Mail_Workbook(ToString As String, SubjectString As String, BodyString As String, _
    Optional CCString As String, Optional BCCString As String, Optional AttachmentName As String)
    Dim OutApp As Object
    Dim OutMail As Object

*********** Set OutApp = CreateObject("Outlook.Application")
*********** Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
   ' Change the mail address and subject in the macro before you run it.
    With OutMail
        .To = ToString
        If CCString <> "" Then
            .CC = CCString
        End If
        If BCCString <> "" Then
            .BCC = BCCString
        End If
        .Subject = SubjectString
        .Body = BodyString
        If AttachmentName <> "" Then
            .Attachments.Add (AttachmentName)
        End If
        
        ' Add special to paste table
        '.HTMLBody = RangetoHTML(Sheets("Body Picture").Range("$A$1:$N$2"))
        
        .Send
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

--------------------
Dan

One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.
Please zip and attach samples. It makes life easier for those who have to figure out what you are trying to do. Thanks
Go to the top of the page
 
cheekybuddha
post Oct 1 2018, 10:38 AM
Post#7


UtterAccess VIP
Posts: 11,702
Joined: 6-December 03
From: Telegraph Hill


I'm slightly confused, Dan. So, this code resides in Outlook? Or Excel?

If the code is in Outlook, then just use the Application object directly instead of creating olApp object variable (like you would were you in Excel and need to refer to the (Excel) Application object).

(Or you can just Set olApp = Application if you don't want to change the code too much.)

Or am I getting it all the wrong way round?

d

--------------------


Regards,

David Marten
Go to the top of the page
 
ADezii
post Oct 1 2018, 12:59 PM
Post#8



Posts: 2,690
Joined: 4-February 07
From: USA, Florida, Delray Beach


My apologies for not being very clear. My idea was to:
  1. Create a Single, Global Instance of Outlook that will persist as long as the Database is running, in this scenario I'm using a Form. As it stands now, every time that MailAlert() and Mail_Workbook() are called, you are creating and destroying an Outlook Instance. Try Declaring the Object Variables representing the Outlook Application and NameSpace publically in a Standard Code Module, as in:
    CODE
    Public oLook As Object      'will represent an Instance of Outlook
    Public olns As Object         'Outlook NameSpace
  2. Create a Single Instance of Outlook along with a NameSpace when the Form Opens, or in a similar environment:
    CODE
    Private Sub Form_Open(Cancel As Integer)
    Set oLook = CreateObject("Outlook.Application")
    Set olns = oLook.GetNamespace("MAPI")
    End Sub
  3. I have parallelled the multiple E-Mail notifications by creating a Recordset of Students, looping thru it, and send an E-Mail to each Student, all with a single Instance of Outlook. The Student's First Name, Last Name, and E-Mail Address is passed to a Public Procedure.
    CODE
    Dim MyDB As DAO.Database
    Dim rst As DAO.Recordset


    Set MyDB = CurrentDb
    Set rst = MyDB.OpenRecordset("Students", dbOpenForwardOnly)

    Do While Not rst.EOF
      Call SendEMails(rst![StudentFirstName], rst![StudentLastName], rst![EMail])
        rst.MoveNext
    Loop

    rst.Close
    Set rst = Nothing
  4. Procedure Definition:
    CODE
    Public Sub SendEMails(strFirst As String, strLast As String, strEMail As String)
    Dim oMail As Object

    Set oMail = oLook.CreateItem(0)

    With oMail
      .To = strEMail
      .Body = "Attached, please find a Summary Report for " & _
               strFirst & " " & strLast
      .Subject = "Student Student Report"
        .Display
    End With
    End Sub
  5. After all is said and done, Set the Object Variables to Nothing, in this case the Close() Event of the Form.
    CODE
    Private Sub Form_Close()
    Set olns = Nothing
    Set oLook = Nothing
    End Sub
  6. I have attached a simple Demo if you are interested. Again, I am not saying that this will resolve your issue, it's simply ad idea on my part.

P.S. - Just realized that you are running the Code within Outlook, obviously much of what I have posted will not apply. pullhair.gif
This post has been edited by ADezii: Oct 1 2018, 01:02 PM
Attached File(s)
Attached File  Single_Outlook_Instance_Demo.zip ( 32.74K )Number of downloads: 3
 
Go to the top of the page
 
dflak
post Oct 1 2018, 01:09 PM
Post#9


Utter Access VIP
Posts: 6,286
Joined: 22-June 04
From: North Carolina


Hey David. The Mail Alert code is Outlook. I got this from the web and modified it.

The Mail_Workbook code is something from my personal library and is something I wrote for Excel. I took it as is and threw it into the code that is running in Outlook.

I think I am getting the picture here. My piece of code, at least is designed to be stand alone and assume that Outlook isn't running. I am not sure why the Mail Alert code starts up a new instance of Outlook since it is running *IN* Outlook.

The code runs perfectly most of the time. The only time it freezes Outlook is when I am drafting an email or a response. In other words, at the worst possible time.

Adezii, I will look at what you provided. I don't have time to digest it at the moment.

Either way, I'll report back and thanks to both for chiming in.

--------------------
Dan

One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.
Please zip and attach samples. It makes life easier for those who have to figure out what you are trying to do. Thanks
Go to the top of the page
 
cheekybuddha
post Oct 1 2018, 02:42 PM
Post#10


UtterAccess VIP
Posts: 11,702
Joined: 6-December 03
From: Telegraph Hill


Again, I may have misunderstood, but it looks like ADezii is thinking the code lives in Access.

If the code lives in Outlook, then CreateObject() or Dim olApp As New Outlook.Application will open another instance in memory.

Much as you wouldn't use Set xlApp = New Excel.Application from within Excel (unless you specifically wanted a separate instance).

Within Outlook you can refer to the existing Application object, just like you might from within Excel.

It appears the code you found is for automating Outlook from another application like Access or Excel.

That said, I haven't had time to go through the code in any detail, so I may be way off the mark!

d

--------------------


Regards,

David Marten
Go to the top of the page
 
dflak
post Oct 1 2018, 03:08 PM
Post#11


Utter Access VIP
Posts: 6,286
Joined: 22-June 04
From: North Carolina


You are correct, David. At least when it comes to my code (Mail_Workbook). The other code apparently does this as well.

You got me thinking and you got me debugging. I have something that works without opening new instances of Outlook. Now whether this will cure the freeze problem remains to be seen.

Here is the new code with what is NOT needed commented out:

CODE
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerfunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long

Public TimerID As Long 'Need a timer ID to eventually turn off the timer. If the timer ID <> 0 then the timer is running

Public Sub ActivateTimer(ByVal nMinutes As Long)
  nMinutes = nMinutes * 1000 * 60 'The SetTimer call accepts milliseconds, so convert to minutes
  If TimerID <> 0 Then Call DeactivateTimer 'Check to see if timer is running before call to SetTimer
  TimerID = SetTimer(0, 0, nMinutes, AddressOf TriggerTimer)
  If TimerID = 0 Then
    MsgBox "The timer failed to activate."
  End If
End Sub

Public Sub DeactivateTimer()
Dim lSuccess As Long
  lSuccess = KillTimer(0, TimerID)
  If lSuccess = 0 Then
    MsgBox "The timer failed to deactivate."
  Else
    TimerID = 0
  End If
End Sub

Public Sub TriggerTimer(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idevent As Long, ByVal Systime As Long)
  ' MsgBox "The TriggerTimer function has been automatically called!"
  ' Place VB Code Here
  Call MailAlert
End Sub

Sub MailAlert()
Dim olApp As Object                     ' Outlook Application
Dim olNS As Object                      ' Outlook Name Space
Dim FldrIn As Object                    ' Dock Schedule folder
Dim FldrOut As Object                   ' Dock Schedule processed folder

Dim olAtt As Object                     ' Outlook attachement
Dim MailBox As String                   ' Labor Analysis mailbox
Dim MailFolders() As String             ' Array of mail folders
Dim FolderNum As Long                   ' Folder number
Dim InFolder As String                  ' Mail folder to check

'Dim shL As Worksheet                    ' Mail message
Dim cl As String                         ' Generic Pointer
Dim MailBody As String                  ' Mail Body
Const olMailItem As Long = 0

On Error GoTo ErrorExit

' Initalize variables
MailBox = "Labor Analysis"
MailBody = ""
MailFolders = Split("Amazon Daily Ops Reports,Amazon Dock Master Data,Amazon Forecast,Amazon Primary Volume Drivers,Cube Reports,Lulus,Pepsi Ops Rpt", ",")


' Set up mailbox
'Set olApp = CreateObject("Outlook.Application")
'Set olNS = olApp.GetNamespace("MAPI")
Set olNS = GetNamespace("MAPI")
For FolderNum = 0 To UBound(MailFolders)
    InFolder = MailFolders(FolderNum)
    Set FldrIn = olNS.Folders(MailBox).Folders("Inbox").Folders(InFolder)
    DoEvents
    If FldrIn.Items.Count > 0 Then
        MailBody = MailBody & "Folder " & InFolder & " has " & FldrIn.Items.Count & " items." & Chr(10)
    End If
Next FolderNum

' Clean up Outlook
'Set FldrIn = Nothing
'Set olNS = Nothing
'Set olApp = Nothing

If MailBody <> "" Then
    ' Mail the message
    Mail_Workbook "daniel.flak@xpo.com", "Data Mail Alert!", MailBody
End If

Exit Sub

ErrorExit:
MsgBox Err.Number & Chr(10) & Err.Description, vbOKOnly, "An error has occurred."
End Sub


and

CODE
Sub Mail_Workbook(ToString As String, SubjectString As String, BodyString As String, _
    Optional CCString As String, Optional BCCString As String, Optional AttachmentName As String)
    Dim OutApp As Object
    Dim OutMail As Object

    'Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = CreateItem(0)

    On Error Resume Next
   ' Change the mail address and subject in the macro before you run it.
    With OutMail
        .To = ToString
        If CCString <> "" Then
            .CC = CCString
        End If
        If BCCString <> "" Then
            .BCC = BCCString
        End If
        .Subject = SubjectString
        .Body = BodyString
        If AttachmentName <> "" Then
            .Attachments.Add (AttachmentName)
        End If
        
        ' Add special to paste table
        '.HTMLBody = RangetoHTML(Sheets("Body Picture").Range("$A$1:$N$2"))
        
        .Send
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    'Set OutApp = Nothing
End Sub

--------------------
Dan

One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.
Please zip and attach samples. It makes life easier for those who have to figure out what you are trying to do. Thanks
Go to the top of the page
 
cheekybuddha
post Oct 1 2018, 04:57 PM
Post#12


UtterAccess VIP
Posts: 11,702
Joined: 6-December 03
From: Telegraph Hill


I would ad back in (uncomment) the lines setting FldrIn and olNS to Nothing.

Even though the object variables should be destroyed when they go out of scope at the end of the proc, it doesn't harm to be explicit - good maxim: unset whatever you set.

Let us know whether it solves your issue.

hth,

d

--------------------


Regards,

David Marten
Go to the top of the page
 
dflak
post Oct 3 2018, 11:36 AM
Post#13


Utter Access VIP
Posts: 6,286
Joined: 22-June 04
From: North Carolina


Even with the cleanup, I've had an instance of a freeze.

It only happens when I am composing or responding to an email. Under normal circumstances, Outlook takes up a fraction of a percent of the processor. When it locks up, it's taking 25%.

I wish I knew what was going on so I could abort whatever was happening. I can deal with On Error GoTo. Too bad there isn't a On Freeze GoTo.

--------------------
Dan

One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.
Please zip and attach samples. It makes life easier for those who have to figure out what you are trying to do. Thanks
Go to the top of the page
 
cheekybuddha
post Oct 8 2018, 05:59 AM
Post#14


UtterAccess VIP
Posts: 11,702
Joined: 6-December 03
From: Telegraph Hill


Sorry Dan, the notifications from UA come in such a random order I only just got the one about your latest reply.

I just noticed that in sub Mail_Workbook() you have On Error Resume Next.

Do you think this might be masking the problem?

Also, you may want to hold your public variable TimerID in a TempVar (or in a private variable, which you set/return via public functions). It could be losing its value if an unhandled error occurs, yet the timer may remain in memory and you then create more.

hth,

d

--------------------


Regards,

David Marten
Go to the top of the page
 
JonSmith
post Oct 8 2018, 06:07 AM
Post#15


UtterAccess VIP
Posts: 4,053
Joined: 19-October 10



I still maintain the 'freeze' is a hidden dialog rather than an actual freeze and changing the code might not help until you discover what that dialog might be? Perhaps a warning to save something.
Go to the top of the page
 
dflak
post Oct 8 2018, 08:16 AM
Post#16


Utter Access VIP
Posts: 6,286
Joined: 22-June 04
From: North Carolina


The on error resume next is in the mailer part of the code. This does not get called when there is no mail to report, but freezes occur anyway. So the issue is most likely not in that part of the code.

I am going to try something else. I had a version of this that I ran from Excel. The task scheduler runs the task when I log in and fires it off every 15 minutes. This task opens the Excel sheet which has a macro to launch its own instance of Outlook, do the work in less than a number of seconds and then close. So it is not something that is running constantly in the background in Outlook.

The issue with this code was that it interfered with any spreadsheets that I happened to have open at the time. However, I called the Excel executable by the path name without any arguments which means, by default, it opens in the same instance of Excel as the last workbook opened. I will revisit this code and call it with the -x option meaning open in a new instance of Excel.

I have to wait for the "Monday Madness" to subside before I have a chance to do this.

I use the Excel spreadsheet because I know how to use the task scheduler to call macros in Excel. I could not find anything on using the task scheduler to call anything in Outlook. However, if I get it working, I'll keep it. I can give it to people and they can fill out the main mailbox and subordinate folders and who to mail it to - all in cells in the workbook. These are defined in the code in the Outlook version. It's easy to access and change, but still requires opening the editor, etc. For a less knowledgeable user, it will be easier to "fill in the blanks."

I will post back if I get this working.

--------------------
Dan

One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.
Please zip and attach samples. It makes life easier for those who have to figure out what you are trying to do. Thanks
Go to the top of the page
 
JonSmith
post Oct 8 2018, 08:20 AM
Post#17


UtterAccess VIP
Posts: 4,053
Joined: 19-October 10



Just add logging to a text file at all parts of your code. see where the freeze occurs. All this guessing isn't helpful. Pinpoint what code is firing when the code freezes and you know where to look.
Go to the top of the page
 
dflak
post Oct 8 2018, 04:07 PM
Post#18


Utter Access VIP
Posts: 6,286
Joined: 22-June 04
From: North Carolina


What do you mean by logging? I am not familiar with it. Where would the data be recorded?

--------------------
Dan

One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.
Please zip and attach samples. It makes life easier for those who have to figure out what you are trying to do. Thanks
Go to the top of the page
 
dflak
post Oct 9 2018, 08:55 AM
Post#19


Utter Access VIP
Posts: 6,286
Joined: 22-June 04
From: North Carolina


In true Edison tradition, I've found one more way that does not work. Opening the macro in a separate version of Excel still interferes with already open worksheets.

I'm back to using the Outlook code, but I liberally sprinkled DoEvents all over the place.

--------------------
Dan

One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.
Please zip and attach samples. It makes life easier for those who have to figure out what you are trying to do. Thanks
Go to the top of the page
 
JonSmith
post Oct 9 2018, 09:05 AM
Post#20


UtterAccess VIP
Posts: 4,053
Joined: 19-October 10



Sorry dude, didn't follow up.

So if you write some code that logs the current sub or function to a text file thats a start (Just create a small function to handle this and call the function at the top of every procedure.). Its also a good idea to log an 'end' event for each procedure.

This might narrow it down to a particular procedure you are having trouble with. Once you identify the last procedure to be called before the freeze you have some focus.
Add some more logging in that proc that, eventually, will indicate the last line to run before the code 'freezes'. Then you know specifically which line to focus on.
Go to the top of the page
 
3 Pages V  1 2 3 >


Custom Search


RSSSearch   Top   Lo-Fi    19th November 2019 - 06:43 PM