Tantrum time ...Run time error91 (1 Viewer)

GaryPanic

Smoke me a Kipper,Skipper
Local time
Today, 10:57
Joined
Nov 8, 2005
Messages
3,309
Hi guys -- been a long time

OK I have a email fuction that sudden has a tantrum and comes up with runtime error 91 ...
but I have been using this for a couple of years and its only now kicked in this week -

any ideas why - I will post the code etc up or should I see if an update has been release last weekend to see if that screwed it up?
 
here is the issue bit (been fine for two years or so )



Set mi = FindSentItem(ID, sentAfter)

Sentstamp = mi.SentOn
' E-mail has been sent
If Not (mi Is Nothing) Then


so its going int runtime error 91 :
Object Variable or with block variable not set
 
Walk your code. Looks like the object was not instantiated for some reason.
Walking the code, should highlight the cause?
 
Obviously, FindSentItem(ID, sentAfter) is not instantiating and returning an object (I guess that is an Email object).
So my guess the code in FindSentItem is failing for some reason and never assigning a return object. So without seeing your code for FindSentItem now way we can guess.
 
here is the issue bit (been fine for two years or so )



Set mi = FindSentItem(ID, sentAfter)

Sentstamp = mi.SentOn
' E-mail has been sent
If Not (mi Is Nothing) Then


so its going int runtime error 91 :
Object Variable or with block variable not set
Something changed. Access doesn't just arbitrarily change the way it works on its own. (With the possible exception of corruption or update bugs).

So, one thing that I always want to evaluate when a process has worked for years and then stops working is the data. Is the data being processed still consistent with the expectations it was based on originally.

The snippet shared above indicates you are calling a function called FindSentItemID with two parameters, ID and sentAfter.

Of the two, the more suspicious to me is the sentAfter. What is that? A date? If so, are you sure a valid date is being passed when the process fails?
 
findSentItem_start:
With sfolder
' With olkns.GetDefaultFolder(olFolderSentMail)
Set items = .items.Restrict("[SentOn] >= '" & Format(sentFromTime, "ddddd h:nn AMPM") & "'")
For Each item In items
If TypeName(item) = "MailItem" Then
If item.Categories = itemID Then
Set FindSentItem = item
Exit Function
End If
End If
Next item
End With

so
setstamp now empty (which I don't get??as I have not touched a thing) could it be a format issue (again i have not change anything)

the email get sent - great its the stamping ( which then triggers the filing )
I don't really want to rewrite the process but its looking like I might have to ?
 
Please use the </> for code
Code:
With sfolder
' With olkns.GetDefaultFolder(olFolderSentMail)
    Set items = .items.Restrict("[SentOn] >= '" & Format(sentFromTime, "ddddd h:nn AMPM") & "'")
    For Each item In items
      If TypeName(item) = "MailItem" Then
        If item.Categories = itemID Then
        Set FindSentItem = item
         Exit Function
        End If
      End If
    Next item
End With

Clearly you have code that does not set a return object if nothing found matching the requirements.
So any well written code needs to check for that case

Code:
Set mi = FindSentItem(ID, sentAfter)
If mi is Nothing then
  Msgbox "There was an issue in returning the sent item",vbinformation
else
  continue your code
....
end if
 
I will add this in - but just seems weird that its playing up now
I will give it a go in 10 mins or so
 
You can also put it in the function itself
Code:
With sfolder
' With olkns.GetDefaultFolder(olFolderSentMail)
    Set items = .items.Restrict("[SentOn] >= '" & Format(sentFromTime, "ddddd h:nn AMPM") & "'")
    For Each item In items
      If TypeName(item) = "MailItem" Then
        If item.Categories = itemID Then
        Set FindSentItem = item
         Exit Function
        End If
      End If
    Next item
   
    If FindSentItem is nothing then
      msgbox "No Mail Item sent after " & Format(sentFromTime, "ddddd h:nn AMPM")
    end with
   
   
End With
 
but just seems weird that its playing up now
It is not "Playing up". Code does not stop working. Obviously conditions have changed with the folder or mail items and your critieria is no longer met.
 
I will add this in - but just seems weird that its playing up now
I will give it a go in 10 mins or so
As I suggested, one reason it might not be finding a matching item is that the current data does not include any qualifying records!

You re looking for items sent on or after a specific data and time, as well as items that match a specific category.
 
ok the message popped up - so that's one thing (many thanks) - but isn't solving the underlying issue
 
As I suggested, one reason it might not be finding a matching item is that the current data does not include any qualifying records!

You re looking for items sent on or after a specific data and time, as well as items that match a specific category.
 
Yes its looking for the ID (stored in the catagories in outlook)


ID = Format(Now(), "yyyymmddhhnnss") & "_" & CInt(1000 * Rnd()) + 1
' Save date and time
sentAfter = Now()
' Change mail item properties




With mi


.To = Nz(Me.email)
.Subject = Subjectz
.Categories = ID
 
1741357977153.png
as an example
 
#it might be outlook it's not running fast- so my code is going faster than outlook and looking for something that might not of been sent (In outbox rather than sent)

I will revert one way or the other - I don't have access to Outlook controls -so I need to get my techies to resolve
 
We get the idea of what you are looking for.

What we are suggesting is that the request is not finding matching items by date and category in the CURRENT items in your email.

For example, the way ID is defined involves a calculated value. It's calculated. Are you sure there are actually values in the Outlook categories that exactly match that calculate value?
I'm afraid that seeing only disjointed snippets of code from different functions paints an incomplete picture that makes it harder to identify possible failure points.

All we can say for sure is that no items currently in your Outlook folder match both the category ID and are latter than or equal to the sentAfter time.
 
#it might be outlook it's not running fast- so my code is going faster than outlook and looking for something that might not of been sent (In outbox)

I will revert one way or the other - I don't have access to Outlook controls -so I need to get my techies to resolve
Exactly. Your code relies in split second timing, it would appear.
 
Question: Does this now ALWAYS fail or only occasionally fail? Does other mail code also fail or only this routine? (Trying to determine the scope of the error.)

A horrible thought if all of your mail automation code suddenly has stopped working... did you accidentally switch to New Outlook? Because if so, you need to switch back immediately if not sooner. But if other VBA mail code is working, then that isn't the problem.

By any chance, did this problem start popping up on a Wednesday morning? Because Microsoft publishes patches every other Tuesday night and you might have run afoul of a foul patch. You can do Windows (Start) >> Settings >> Windows Updates and browse around on that page to find History to see what patches have recently been loaded - and WHEN.
 

Users who are viewing this thread

Back
Top Bottom